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

2 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Find more on File Operations in Help Center and File Exchange

产品

Community Treasure Hunt

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

Start Hunting!

Translated by