I want to output text in a text file.

조회 수: 4 (최근 30일)
日凯 林
日凯 林 2022년 11월 24일
편집: Stephen23 2022년 11월 24일
I want to output text in a text file. There are some data that need to be replaced, such as endtime. I used% d, but when I finished outputting, I found that% d was not replaced by endtime. The output is still% d. I want to ask what I did wrong?
  댓글 수: 2
日凯 林
日凯 林 2022년 11월 24일
The code is as follows
The cfprintf(newfid,'%s\n','$# endtim endcyc dtmin endeng endmas nosol');
fprintf(newfid,'%s\n',' %d 0 0.0 0.01.000000E8 0',endtime);
Stephen23
Stephen23 2022년 11월 24일
편집: Stephen23 2022년 11월 24일
"I used% d, but when I finished outputting, I found that% d was not replaced by endtime. The output is still% d. I want to ask what I did wrong?"
You wrote %d in the input text (for which all characters are interpreted literally), rather than in the format string (where special characters are used as you expect, to specify how to display the input arguments).
fprintf(newfid,'%s\n',' %d 0 0.0 0.01.000000E8 0',endtime);
% ^^^^^^ format string, special characters.
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ input argument, literal text only!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by