defining string variable in fprintf function

44 visualizaciones (últimos 30 días)
sermet OGUTCU
sermet OGUTCU el 12 de Jul. de 2021
Respondida: Star Strider el 12 de Jul. de 2021
result_1=10.5;
result_2=9.9;
string1='data1';
string2='data2';
fprintf(fid','string1 %.1f string2 %.1f\n', result_1, result_2);
In the above example, string1 and string2 are written in text file along with theirs' results. How can I define string1 and string2 as variables (data1, data2) in fprintf function?

Respuesta aceptada

Star Strider
Star Strider el 12 de Jul. de 2021
Try this —
fid = 1; % Write To Command Window
result_1=10.5;
result_2=9.9;
string1='data1';
string2='data2';
fprintf(fid,'%s %.1f %s %.1f\n', string1, result_1, string2, result_2);
data1 10.5 data2 9.9
.

Más 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