필터 지우기
필터 지우기

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
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');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by