フィルターのクリア

How to solve error "Index exceeds matrix dimensions" when reading netcdf file?

2 ビュー (過去 30 日間)
Shayma Al Ali
Shayma Al Ali 2020 年 10 月 16 日
回答済み: meghannmarie 2020 年 10 月 16 日
I'm trying to import some variables from a netcdf file. The variable "wind speed" has dimensions of 1x1x42456 or lat xlon x time. My current code is
datl.wspd=[];datl.time=[]; datl.datenum=[];
datl.time=ncread(direc(i).name,'time'); %load times from fix
for i=1:length(datl.time)
datl.datenum(i)=addtodate(datenum(1970,1,1),fix(datl.time(i)),'second');
end
% for j=1:length(datl.time)
% datl.datenum(j)=datenum(1970,1,1)+datl.time(j);
% end
tstart=min(datl.datenum);
tend=max(datl.datenum);
datl.datenum=datl.datenum';
datl.wspd=zeros(1,1,length(datl.datenum));
datl.wspd(:,:,:,i)=ncread(direc(i).name,'wind_spd'); %load wspd from file
but I always end up with the error "Index exceeds matrix dimensions". How can I resolve this?

回答 (1 件)

meghannmarie
meghannmarie 2020 年 10 月 16 日
datl.wspd has 3 dimensions but when you save data to it you are indexing into a fourth dimension. I think your last line should be this:
datl.wspd(:,:,i)=ncread(direc(i).name,'wind_spd'); %load wspd from file

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by