Borrar filtros
Borrar filtros

What is the syntax of fprintf? Suppose there are two flot numbers 1 and 2, and F_ID is the file identifier. Write the command to sabe the two numbers to F_ID?

1 visualización (últimos 30 días)
What is the syntax of fprintf? Suppose there are two flot numbers 1 and 2, and F_ID is the file identifier. Write the command to sabe the two numbers to F_ID?

Respuesta aceptada

Wayne King
Wayne King el 9 de Feb. de 2014
Editada: Wayne King el 9 de Feb. de 2014
fprintf(F_ID, '%1.1f %1.1f\n', X)
where X has two columns. X is the variable in the MATLAB workspace contain the numbers.
Or
fprintf(F_ID, '%1.1f %1.1f\n', a,b)
where a = 1.0 and b = 2.0

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 9 de Feb. de 2014
x=[1 2]
fid=fopen('filename.txt','w')
fprintf(fid,'%10.1f',x)
fclose(fid)

Image Analyst
Image Analyst el 9 de Feb. de 2014
Editada: Image Analyst el 10 de Feb. de 2014
In regards to your question "What is the syntax of fprintf? Suppose there are two flot numbers 1 and 2, and F_ID is the file identifier. Write the command to sabe the two numbers to F_ID?"
fprintf(F_ID, '%f, %f\n', number1, number2);
That will put them on their own line, separated by a comma. If you want a certain number of decimal places, say 3, then do it like this:
fprintf(F_ID, '%.3f, %.3f\n', number1, number2);

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by