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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by