Using fprintf to print to a text file

29 ビュー (過去 30 日間)
pxg882
pxg882 2014 年 3 月 23 日
コメント済み: Image Analyst 2014 年 3 月 23 日
This prints my 6 sets of data as one continuous column of data in a .txt file.
fileID = fopen('nN_10.txt','w');
fprintf(fileID,'%.8f\r\n',X(:,1), X(:,2), X(:,10), X(:,4), X(:,5), X(:,6));
fclose(fileID);
That's fine, I would just like to insert one blank line between each set of data. I imagine the solution is particularly easy but I can't seem to find it anywhere!
Thanks.

回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 23 日
編集済み: Image Analyst 2014 年 3 月 23 日
Try this:
fprintf(fileID, '%f\n', x(:,1));
fprintf(fileID, '\n');
fprintf(fileID, '%f\n', x(:,2));
fprintf(fileID, '\n');
fprintf(fileID, '%f\n', x(:,3));
fprintf(fileID, '\n');
fprintf(fileID, '%f\n', x(:,4));
fprintf(fileID, '\n');
fprintf(fileID, '%f\n', x(:,5));
fprintf('\n');
fprintf('%f\n', x(:,6));
fprintf('\n');
Also, open the file as 'wt' instead of 'w'. You can probably get rid of the \r then also, but maybe not - it depends on what you use to open the file with (e.g. notepad or wordpad).
  2 件のコメント
pxg882
pxg882 2014 年 3 月 23 日
Perfect, thanks!
Image Analyst
Image Analyst 2014 年 3 月 23 日
If we're done here, can you officially mark as "Accepted" to let others know we're done? Thanks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeElectrical Block Libraries についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by