I want to output text in a text file.

5 visualizzazioni (ultimi 30 giorni)
日凯 林
日凯 林 il 24 Nov 2022
Modificato: Stephen23 il 24 Nov 2022
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 Commenti
日凯 林
日凯 林 il 24 Nov 2022
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 il 24 Nov 2022
Modificato: Stephen23 il 24 Nov 2022
"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!

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by