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

55 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 25 Oct 2013
fprintfコマンドでテキストファイルに書き出したデータが改行されません。

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 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)

Plus de réponses (0)

Produits


Version

R2008a

Community Treasure Hunt

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

Start Hunting!