I would like to use fprintf to save the following line as a text file.
%%number of points: x
x is a variable and for instance x=25
%%number of points: 25
thank you very much

2 Comments

And what aspect of it is causing you a problem?
I do not know how to write it

Sign in to comment.

 Accepted Answer

fid=fopen('your_file.txt','w')
x=25
str=sprintf('number of points: %d',x)
fprintf(fid,'%s',str)
fclose(fid)

4 Comments

Many thanks.
It should be like this:
%% number of points: 25
fid=fopen('your_file.txt','w')
x=25
str=sprintf('%%%%number of points: %d',x)
fprintf(fid,'%s',str)
fclose(fid)
thanks a lot
I would just go for
fid = fopen('your_file.txt', 'w');
x = 25;
fprintf(fid, '%%%%number of points: %d\n', x);
fclose(fid);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!