Loading a dat file in Matlab

3 visualizaciones (últimos 30 días)
Jason
Jason el 26 de Oct. de 2014
Respondida: Star Strider el 26 de Oct. de 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',' ');

Respuestas (1)

Star Strider
Star Strider el 26 de Oct. de 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:

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by