Borrar filtros
Borrar filtros

Chnage number display format

3 visualizaciones (últimos 30 días)
Damith
Damith el 23 de Mayo de 2014
Comentada: Damith el 24 de Mayo de 2014
Hi,
The numbers in the first column of my output writing to a text file shows like 3e+006.
But I want to display like 3000001.
How can I change that in MATLAB?
Thanks.

Respuestas (1)

Sean de Wolski
Sean de Wolski el 23 de Mayo de 2014
How are you writing it right now? If you are using fprintf you can change the format spec. For example:
fprintf(1,'%10.0f\n',randi(10,[5, 1])*2347348)
  4 comentarios
Damith
Damith el 23 de Mayo de 2014
I sort of figure it out. But I am still struggling to maintain the spacing between 3rd columns and 4th column. There shoud be 3 spacing between col 3 and 4.
sample=dlmread('sample.txt',' ','A2..D10');
dlmwrite('test.txt',sample,'delimiter',' ','precision', 10)
How can I modify the above code to achieve that?
Thanks.
Damith
Damith el 24 de Mayo de 2014
Hi,
I was able to develop the code below. But in the command window I can see the output the way I want to produce. But the test.txt file is blank.
Command window output:
3000001 -99.9 -99.9 0.0
3000002 -99.9 -99.9 0.0
3000003 -99.9 -99.9 0.0
3000004 -99.9 -99.9 0.0
3000005 -99.9 -99.9 0.0
3000006 -99.9 -99.9 0.0
3000007 -99.9 -99.9 0.0
3000008 -99.9 -99.9 0.0
3000009 -99.9 -99.9 0.8
3000010 -99.9 -99.9 0.0
I dont understand what I am doing wrong here and why the test.txt file is bank. I want the command window output to be written in the text file.
sample=dlmread('sample.txt',' ','A2..C11');
Data=[sample(1:10,:) Gist1(1:10,5)];
dlmwrite('test.txt',Data,'delimiter',' ','precision', 10)
fid = fopen('test.txt','wt');
for row = 1 : size(Data, 1);
fprintf('%d %.1f %.1f %3.1f\n', Data(row, :));
end
fclose(fid);
Can somebody help me to figure out what I am missing here.
Many thanks in advance.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by