Writing zero to text file

2 visualizaciones (últimos 30 días)
Andrew
Andrew el 22 de Oct. de 2013
Comentada: Andrew el 22 de Oct. de 2013
I am trying to write the number 0 to a text file with a certain amount of precision, ie 0.00000, currently I am using fprintf(fid, num2str(0,6)), which should write the number with 6 decimal places, but it does not work, I was wondering if there is a proper way to do this(other than adding an extremely small offset to the zero) thanks.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Oct. de 2013
Editada: Azzi Abdelmalek el 22 de Oct. de 2013
A=[1.23;52;14.356]
fid=fopen('file.txt','w')
fprintf(fid,'%.5f\n',A)
fclose(fid)

Más respuestas (1)

sixwwwwww
sixwwwwww el 22 de Oct. de 2013
Dear Andrew, you can write the 0s in the text file in the following way:
a = {'0.00000', '0.00000', '0.000000'};
ID = fopen('filename.txt', 'w');
fprintf(ID, '%s\n', a{:});
fclose(ID)
I hope it helps. Good luck!
  1 comentario
Andrew
Andrew el 22 de Oct. de 2013
In this paticular situation I needed to print a number to the file, whereas here you are printing a string. The other answer works in my case, thanks for the help though.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands 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