fprintfコマン​ドでテキストファイル​に書き出したデータが​改行されません。

55 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
fprintfコマンドでテキストファイルに書き出したデータが改行されません。

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
Windows環境では文字コードの関係で、テキストを改行するために、ニューライン(\n)だけでは改行されない場合があります。
対応方法として、次の2つの方法があります。
(1) fopen するときに、テキストモード('t')を指定してオープン
例:
fid = fopen('out.txt','wt');
fprintf(fid,'%i\n',3);
fclose(fid)
(2) fprintf で改行コードとして、ニューライン(\n)だけではなくキャレッジリターン(\r)も与え、'\r\n' と指定する
例:
fid=fopen('out.txt','w');
fprintf(fid,'%i\r\n',3);
fclose(fid)

More Answers (0)

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!