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

Adam
Adam 2016년 6월 13일
And what aspect of it is causing you a problem?
Maryam Hamrahi
Maryam Hamrahi 2016년 6월 13일
I do not know how to write it

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 13일

0 개 추천

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

댓글 수: 4

Maryam Hamrahi
Maryam Hamrahi 2016년 6월 13일
Many thanks.
It should be like this:
%% number of points: 25
Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 13일
편집: Azzi Abdelmalek 2016년 6월 13일
fid=fopen('your_file.txt','w')
x=25
str=sprintf('%%%%number of points: %d',x)
fprintf(fid,'%s',str)
fclose(fid)
Maryam Hamrahi
Maryam Hamrahi 2016년 6월 13일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by