Filter löschen
Filter löschen

Loading a dat file in Matlab

1 Ansicht (letzte 30 Tage)
Jason
Jason am 26 Okt. 2014
Beantwortet: Star Strider am 26 Okt. 2014
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',' ');

Antworten (1)

Star Strider
Star Strider am 26 Okt. 2014
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:

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by