Loading a dat file in Matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
In my "global_v1" mathlab script, I'm trying to load data from the file "GlobalTemp_v2.dat" I am interested in column 14 (the temperature) and column 1 (the year). When I run the script, the 14th column of "data1" only contains three NaN values. How do I load the data? Thanks.
This is the link to my DAT file: https://www.dropbox.com/s/77qyr6vhg4ahgs2/GlobalTemp_v2.dat?dl=0
Here is my code:
fid1 = fopen('GlobalTemp_v2.dat'); % have 20 columns
format = '%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ';
data1 = textscan(fid1, format, 'HeaderLines', 6,'delimiter',' ');
댓글 수: 0
답변 (1개)
Star Strider
2014년 10월 26일
There were a couple small problems in your code. First, there are 8 header lines, and the appropriate delimiter may be '\n'.
This works:
fid1 = fopen('GlobalTemp_v2.dat'); % have 20 columns
data1 = textscan(fid1, repmat('%f ', 1, 20), 'HeaderLines',8, 'Delimiter','\n');
Date = data1{1}; % Date (Calendar Years)
Temp = data1{14}; % Temperature
figure(1)
plot(Date, Temp)
grid
xlabel('Year')
ylabel('T (°F)')
The plot is just for fun for me, since I wanted to see what the data look like:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!