How can I save the outputted string (retaining tabs/added lines) to a .txt file?

1 回表示 (過去 30 日間)
Keith Grey
Keith Grey 2020 年 5 月 14 日
コメント済み: Keith Grey 2020 年 5 月 14 日
How can I save the outputted string (retaining tabs/added lines) to a .txt file?
MESSAGE = sprintf('Var1 is %g.\nVar2 is %g.', X, Y);
disp(MESSAGE)
In the Command Window, disp(MESSAGE) outputs:
X is 2.24.
Y is 3.33.

採用された回答

Stephen23
Stephen23 2020 年 5 月 14 日
[fid,msg] = fopen('yourfile.txt','wt');
assert(fid>=3,msg)
fprintf(fid,'%s',MESSAGE);
fclose(fid);
  3 件のコメント
Stephen23
Stephen23 2020 年 5 月 14 日
You mixed up the fopen and sprintf syntaxes. Try this:
[fid,msg] = fopen(sprintf('%s Values.txt', F_Name), 'wt');
Keith Grey
Keith Grey 2020 年 5 月 14 日
That did it! Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by