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

per isakson
per isakson 2018년 5월 13일
Looks like your format string doesn't match the file or the other way round. Please attach the text file.
Walter Roberson
Walter Roberson 2018년 5월 13일
Try delimiter \t instead of /t
FMR
FMR 2018년 5월 13일
this is the text file

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 13일

0 개 추천

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

okay i've updates my codes to this, but still the extraction values for ano (temperature anomalies i wanted) and date (sample size of 2005-2015) are incorrect. Somehow theres 87 rows when there should only be 10 (2005-2015)
% 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
ano = cell2mat(data_anomalies(:,2)); % raw (not interpolated/filled)
ano(ano<0) = NaN; % identify the missing data and set to NaN
% Datenum: point in time as the number of days from January 0, 0000
date = datenum(cell2mat(data_anomalies(:,1)));
%N = datenum(Y,MO,D) and N = datenum([Y,MO,D]) return the serial date
% numbers for corresponding elements of the Y,MO,D (year,month,day)
% arrays. Y, MO, and D must be arrays of the same size (or any can be a
% scalar).
Walter Roberson
Walter Roberson 2018년 5월 13일
편집: Walter Roberson 2018년 5월 13일
'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 2018년 5월 13일
Ahh the little things!! Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Events에 대해 자세히 알아보기

태그

질문:

FMR
2018년 5월 13일

댓글:

FMR
2018년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by