Loading txt data using textscan

7 vues (au cours des 30 derniers jours)
FMR
FMR le 13 Mai 2018
Commenté : FMR le 13 Mai 2018
Hi i'm trying to load some data from a text file from line 137 to 147. the data contains the year and the anomalies values. I tried using this codes but i keep getting these errors:
Index exceeds matrix dimensions.
Error in anomalies (line 6)
A = cell2mat(data_anomalies(137:147,2:13)); % raw (not interpolated/filled)
& my data_anomalies contains the value "14x1 double".
% Load the data
fileID = fopen('../pdata/GISS_NH_temp_anomalies.txt','r','n');
data_anomalies = textscan(fileID,'%f %f %f %f %f %f %f %f %f %f %f %f %f','Delimiter','/t','HeaderLines',136);
fclose(fileID);
% Extract the specific data required
A = cell2mat(data_anomalies(137:147,2:13)); % raw (not interpolated/filled)
% Datenum: point in time as the number of days from January 0, 0000
Date = datenum(cell2mat(data_anomalies(:,1)));
  3 commentaires
Walter Roberson
Walter Roberson le 13 Mai 2018
Try delimiter \t instead of /t
FMR
FMR le 13 Mai 2018
this is the text file

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Mai 2018
You ask for 136 headerlines. That is 136 lines that will be skipped and not created in the output data. There are only 14 lines left of the 150 in the file, so you cannot index 137 on wards.
  3 commentaires
Walter Roberson
Walter Roberson le 13 Mai 2018
Modifié(e) : Walter Roberson le 13 Mai 2018
'Delimiter', '\t'
Notice \ rather than / and notice that you had a space between the ' and the / in your code.
This gets you 14 lines of output, 2005 to 2018.
FMR
FMR le 13 Mai 2018
Ahh the little things!! Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Time Series Events dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by