fprintf end of line character
16 ビュー (過去 30 日間)
古いコメントを表示
When I use fprintf to print multiple lines of text onto a txt file, it introduces a small rectangular box at the end of each line when ever I use '\n'. How would I print without getting that box at the end of each line of text in txt file?
Thanks, Ganesh
1 件のコメント
Fangjun Jiang
2011 年 5 月 24 日
So, what is the problem? I thought it was due to the text editor that you are using. Why does '\r\n' solve the problem?
採用された回答
Oleg Komarov
2011 年 5 月 24 日
fid = fopen('test.txt','w');
fprintf(fid,'%.0f\t%.0f\r\n', [1:5; 6:10]);
fid = fclose(fid);
0 件のコメント
その他の回答 (4 件)
Jan
2011 年 5 月 24 日
CHAR(10), which is the same as '\n', is a valid line break. Only the dull Windows Editor has problems with the interpretation, but this is a problem of a single outdated program. Some other editors, which can handle the line breaks correctly: The Matlab editor at least since Matlab 5.3, WordPad, Notepad++, Emacs, BBEdit, ...
Using the text mode to write files (fopen(FileName, 'wt')) has some side-effects, which may be very surprising for less experienced programmers.
0 件のコメント
Fangjun Jiang
2011 年 5 月 24 日
What text editor are you using to view your text file? You need your text to appear in separated lines, right? Otherwise, you could just not to include the '\n'.
Try '\r' instead.
0 件のコメント
Walter Roberson
2011 年 5 月 24 日
You should be opening your file with 'wt' instead of 'w' when you want to write text files.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!