Filter löschen
Filter löschen

Amend code to save file in a different format

3 Ansichten (letzte 30 Tage)
hde
hde am 5 Mär. 2012
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?

Antworten (1)

Andrew Newell
Andrew Newell am 5 Mär. 2012
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);

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by