I want to output text in a text file.

5 visualizaciones (últimos 30 días)
日凯 林
日凯 林 el 24 de Nov. de 2022
Editada: Stephen23 el 24 de Nov. de 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 comentarios
日凯 林
日凯 林 el 24 de Nov. de 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 el 24 de Nov. de 2022
Editada: Stephen23 el 24 de Nov. de 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!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by