필터 지우기
필터 지우기

Amend code to save file in a different format

조회 수: 3 (최근 30일)
hde
hde 2012년 3월 5일
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에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by