Amend code to save file in a different format

1 次查看(过去 30 天)
I am having trouble saving a matrix of data that I have accessed from another file and saved into a different format. The code I have used is:
fid = fopen(example.svc','r');
data = textscan(fid,'%f %f %f %f %f %f %f','HeaderLines',1);
fclose(fid);
B=[data{3} data{1} data{2} data{7} data{4} data{5} data{6}];
x=zeros(length(B),1);
D=[data{3} data{1} data{2} data{7} x data{4} x x x data{5} data{6} x x x x];
save example.txt D -ascii
This gives me a text file where the numbers are not readable. The below numbers are from the first row, I have not put in all the numbers from this row. Each row (there are about 156 of them) have numbers like this:
1.9037675e+008 2.4432000e+004 1.7833000e+004 9.0000000e+001 0.0000000e+000 1.0000000e+000 What I would like are numbers like:
24092 14047 190383782 1 0 1340
I would then like to analyse these numbers e.g making totals and dividing etc, but do not think that having numbers in the previous format would be appropriate, as some of the precision is lost e.g. 1.9037675e+008 should be 190376747? Can I save the matrix I made in a better way so that I can use it?

回答(1 个)

Andrew Newell
Andrew Newell 2012-3-5
You could use this code:
fid = fopen('example.txt','w');
fprintf(fid,'%i %i %i %i %i %i %i\n',D);
fclose(fid);
If you want all your numbers to be integers, your input line should be
data = textscan(fid,'%i %i %i %i %i %i %i','HeaderLines',1);

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by