fprintf not working properly

12 ビュー (過去 30 日間)
Sune
Sune 2012 年 2 月 28 日
It's not often that i need to create .txt files with results, so I may have forgotten the procedure, even though it seems rather simple. Nevertheless I find that the output i generate looks wrong.
fid = fopen('output.txt','w+');
for i=1:length(out)
fprintf(fid,'%f\t%s\n',out(i),comment{i});
end
fclose(fid)
Although its rude it should do the job of listing values with a comment next to it on each line. BUT IT JUST CONCATENATES IT INTO ONE LONG STRING. It's rather frustrating, am I doing something wrong, or is anything out of the ordinary on my PC?

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 2 月 28 日
fid = fopen('output.txt','wt+'); %notice the t

Jason Ross
Jason Ross 2012 年 2 月 28 日
I bet whatever you are using to open the file doesn't interpret the newline as a newline. You could try using \r, or you could see if there is a setting in whatever program you are using to honor newline correctly. You could also try another program to open the file (are you using Notepad? Try Wordpad)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by