How do I load ASCII dat file to MATLAB
조회 수: 1 (최근 30일)
이전 댓글 표시
After reading some articles in the forum, I used textscan to load my .dat file to MATLAB. Unfortunately, MATLAB only read the first line of my .dat file.
- load does not work, most likely because 7th column is double followed by "....."
fid=fopen('newtext.dat');
C=textscan(fid,'%d %d %d %d %d %d %d');
this led to
C=
[775841] [644] [552] [1185] [617] [534] [1153]
Any hints or answers to this problem would be appreciated!
Here's a sample of my .dat file:
775841 643.5 551.6 1185.0 617.3 533.6 1153.0 .....
775843 643.6 552.3 1185.0 621.0 531.8 1153.0 .....
775845 643.6 552.9 1185.0 624.7 530.1 1152.0 .....
775847 643.4 553.4 1185.0 625.6 529.7 1153.0 .....
775849 643.1 553.4 1186.0 622.8 530.7 1154.0 .....
775851 642.8 553.5 1187.0 620.0 531.7 1154.0 .....
775853 642.9 554.0 1187.0 616.6 534.4 1154.0 .....
775855 643.1 554.8 1186.0 613.3 537.3 1154.0 .....
775857 643.5 555.5 1185.0 614.4 538.2 1154.0 .....
775859 643.7 555.5 1184.0 618.7 536.3 1155.0 .....
댓글 수: 0
채택된 답변
dpb
2015년 5월 14일
편집: dpb
2015년 5월 14일
fid=fopen('newtext.dat');
fmt=[repmat('%f',1,7) '.....']; % include the junk as pattern matching
C=cell2mat(textscan(fid,fmt,'collectoutput',true));
should give a single array of all the values.
댓글 수: 5
dpb
2015년 5월 14일
"...a missing "'" in the repmat call for the fmt."
Dang! What ya' get's for "air code".
Joseph Cheng
2015년 5월 14일
I just wish "air code" was as flashy as "air guitar". I would like to say most of my typos are "purposely" put to test the person but they are usually just "air code" mistakes.
추가 답변 (1개)
Image Analyst
2015년 5월 14일
편집: Image Analyst
2015년 5월 14일
Please attach the file with the paper clip icon in case anyone wants to try some code on it to help you. Also, maybe the ..... is causing a problem. Maybe either see if you can get rid of it, or try putting ..... into the format string in textscan(). Also, since you're using floating point numbers, not integers, you'll have to use %f instead of %d.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!