add a line to a text file without fprintf?
2 ビュー (過去 30 日間)
古いコメントを表示
Constance Woodman
2017 年 7 月 27 日
編集済み: Walter Roberson
2017 年 7 月 27 日
So, when adding lines to text files I always see
fid = fopen(fileName,'w');
fprintf(fid,'%s\n','content');
fclose(fid);
Can this be done without fprintf, to avoid spending system resources displaying text command window? Or is it somehow necessary to see the text in the command window when writing to a file?
0 件のコメント
採用された回答
Walter Roberson
2017 年 7 月 27 日
編集済み: Walter Roberson
2017 年 7 月 27 日
? That code would not display anything to the command window.
fprintf(fid,...) displays to the command window only if the fid is exactly 1 or exactly 2, and neither of those values will ever be returned by fopen().
But to answer your question:
S = sprintf('%s\n','content');
fid = fopen(fileName,'w');
fwrite(fid, S);
fclose(fid);
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!