Chnage number display format

1 次查看(过去 30 天)
Damith
Damith 2014-5-23
评论: Damith 2014-5-24
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.

回答(1 个)

Sean de Wolski
Sean de Wolski 2014-5-23
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 个评论
Damith
Damith 2014-5-23
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 2014-5-24
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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by