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.
回答(1 个)
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 :
- 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.
- You can preallocate the “idxlon” and “idxlat” arrays before the loop.
- 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
- 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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!