Error to extract 4-D double nc data

1 次查看(过去 30 天)
Hello,
I am having trouble to extract nc data. it shows an error Index in position 1 exceeds array bounds. Index must
not exceed 1.
N=5088
sizelong=length(lon);
sizelat=length(lat);
for jj=1:sizelong;
idxlon(jj)=all(ismember(want1,lon(1:5088,:)));
idxlat(jj)=all(ismember(want2,lat(1:5088,:)));
end
rowId=find(idxlon);
colId=find(idxlat);
Please help.
  2 个评论
Fatihah Shariful
Fatihah Shariful 2022-8-10
I want to extract a data that consist of several variables from a coordinate.

请先登录,再进行评论。

回答(1 个)

Pooja Kumari
Pooja Kumari 2023-9-16
Dear Fatihah,
I understand that you are facing “Index in position 1 exceeds array bounds. Index must not exceed 1” error while trying to extract 4-D nc Data. The error message suggests that there is an issue with the indexing of the arrays, it might be possible that the index values you are using are exceeding the array bounds. Here are the troubleshooting steps for your code :
  1. It might be possible that the issue will be with “idxlon” and “idxlat” arrays as all the column values are stored lon(1:5088,:) and these arrays are initialized inside the loop, which means their size are not predetermined.
  2. You can preallocate the “idxlon and “idxlat” arrays before the loop.
  3. There might be some issue while reading data variable in netCDF data source using “ncdata” function. You can refer to the below documentation for more information on “ncdata” function: https://www.mathworks.com/help/matlab/ref/ncread.html
  4. A similar workaround is given in the following MATLAB Answers you can refer: https://www.mathworks.com/matlabcentral/answers/1608670-how-to-process-nc-file-in-matlab
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by