I want t write a number to a file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jonas Müller
el 2 de Abr. de 2022
Comentada: Voss
el 2 de Abr. de 2022
I want to do this:
fOutput = fopen('test.txt','wt');
fprintf(fOutput,'%5.2d',22.56);
fclose(fOutput);
but the txt file is empty after doing this
0 comentarios
Respuesta aceptada
Voss
el 2 de Abr. de 2022
It seems to work ok here:
fOutput = fopen('test.txt','wt');
fprintf(fOutput,'%5.2d',22.56);
fclose(fOutput);
ls *.txt
type test.txt
It could be that too many files are open already, e.g., because of code that has previously been run.
You can do fclose all to close all open files and then try to write to test.txt again.
2 comentarios
Voss
el 2 de Abr. de 2022
%5.2d
% ^ beginning of formatted text signifier
% ^ 5 characters wide (total width)
% ^^ 2 characters after the decimal point (precision)
% ^ decimal number
%5.2f
% ^ floating-point number
fprintf(1,'%5.2d',22.56)
fprintf(1,'%5.2f',22.56)
More information about formatted text: https://www.mathworks.com/help/matlab/matlab_prog/formatting-strings.html
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!