Need help, Why is Matlab not writing to file?

  • MATLAB
  • Thread starter captain fink
  • Start date
  • #1

Main Question or Discussion Point

clc
clear

f = input('Enter the force applied in lbs: ');
p_c = input('Enter point closest to pivot: ');
p_f = input('Enter point farthest from pivot: ');
filename = input('name of file is: ','s');
points = input(' # of points to calculate: ');

x = [p_c;rand(points,1)*p_f-p_c+p_c;p_f];
y = sort(x);
pos = find(y<p_c);
pos1 = find(y>p_f);
y(pos) = [];
y(pos1) = [];

%disp(y) points

M = y*f;

%disp(M) moment

final = [y,M];

Mo = fopen([filename,'_',f,'_',points,'.txt'], 'w');

%fid = fopen(string, option)

%writing

fprintf(Mo, 'ID:\t%s\nF:\t%2.2f\n point closest:\t%2.3f\n point farthest:\t%2.3f...\n',filename,f,p_c,p_f);
fprintf(Mo, ' points\t moment\n');
fprintf(Mo, '%.2f\t.2f',y,M);
fclose(Mo);

Your thoughts would be helpful because I don't see why this isn't working
 

Answers and Replies

  • #2
1
0
The variables f, and points (which are of type double), are used to generate you file name without being converted to string.
Mo = fopen([filename,'_',f,'_',points,'.txt'], 'w');
Try, using num2str function, for example
Code:
Mo = fopen([filename,'_',num2str(f),'_',num2str(points),'.txt'], 'w');
Also, you might want to have a closer look at:
fprintf(Mo, '%.2f\t.2f',y,M);
think, it's missing a % after \t.
 

Related Threads on Need help, Why is Matlab not writing to file?

  • Last Post
Replies
1
Views
2K
Replies
5
Views
8K
Replies
5
Views
78K
Replies
4
Views
6K
Replies
1
Views
2K
Replies
3
Views
3K
Replies
5
Views
7K
Replies
12
Views
3K
Top