Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
trouble for importing a data file
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I want to import a *.asc file. The file has data something like below.
0.021780 2 768 Rx d 8 21 62 254 157 2 39 255 242
0.042450 2 768 Rx d 8 21 16 2 62 0 158 255 246
I'm tried different commands, but I'm not able to load this as per my requirements.
I tried to use 'importdata' function as shown below
"[A] = importdata('CANOE10.asc', '\t');"
When I use this, all the data is stored in single cell as it is in the file. But, I want to store the data separately in different variables like
A1 = 21, B1= 62, C1 = 254, D1 = 157 etc..
I even tried 'textread' function as like below.
"[C, D, E, F, G, H] = textread('CANOE10.asc', '%s %s %s %s %s %d'); " Using this function, the data was able to store in different variables, but its not able to store consistently.
Kindly help me please.
댓글 수: 0
답변 (2개)
Geoff
2012년 3월 15일
Using textread is fine here.
But you need to include as many fields in your format string as you expect to see in the file, starting from the first. Even if you don't care about the first few columns.
Looking at that example data, I would use the format:
'%f%d%d%s%s%d%d%d%d%d%d%d%d%d'
You have to specify that many variables on the left though.
If you go back to your importdata version, it might be easier.
in = importdata('CANOE10.asc', '\t');
A = in.data(:,1);
B = in.data(:,2);
C = in.data(:,3);
% etc...
댓글 수: 2
Geoff
2012년 3월 15일
Is your data _actually_ tab-delimited? If not, then specifying that it is will cause each row to be read into a single string.
I checked my code by copying your lines verbatim into a file and calling importdata('CANOE10.asc'); That will use spaces as the delimiter, and behaves correctly.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!