Index exceed matrix dimensions.
1 次查看(过去 30 天)
显示 更早的评论
I wrote the following codes, but after commanding it for a run, it is showing that index exceeds matrix dimension and error in testmisr(line 11) if od(a,b,c,d,e)==-9.999. the codes:
for i = 1:30;
filename_apr = ['/Users/Sudipta/Documents/misr daily data/mar00-feb01/061703666281887/MISR_AMI_CGAS_APR_',num2str(i),'_2000_F15_0031.hdf'];
od(i,:,:,:,:,:) = hdfread('F:\Modis_TERRA_daily\MISR_AM1_CGAS_APR_01_2000_F15_0031.hdf', '/AerosolParameterAverage/Data Fields/Optical depth average', 'Index', {[122 538 1 2 1],[1 1 1 1 1],[12 18 1 1 6]});
for a = 1:12;
for f = 1:31
for b = 1:18;
for c = 1:1;
for d = 1:1;
for e = 1:6;
if od(f,a,b,c,d,e)== -9999;
od(f,a,b,c,d,e) = NaN;
else if od(f,a,b,c,d,e)==-9.999;
od(f,a,b,c,d,e) = NaN;
else
od(f,a,b,c,d,e)=od(f,a,b,c,d,e);
end
end
end
end
end
end
end
1 个评论
Chandrasekhar
2014-3-10
index is trying to access the matrix element which doesnt exist. index > length(array/matrix)
回答(1 个)
Patrik Ek
2014-3-10
编辑:Patrik Ek
2014-3-10
You do not need make all these for loops for this. Instead of
for a = 1:12;
for f = 1:31
for b = 1:18;
for c = 1:1;
for d = 1:1;
for e = 1:6;
if od(f,a,b,c,d,e)== -9999;
od(f,a,b,c,d,e) = NaN;
else if od(f,a,b,c,d,e)==-9.999;
od(f,a,b,c,d,e) = NaN;
else
od(f,a,b,c,d,e)=od(f,a,b,c,d,e);
end
end
end
end
end
end
do something like,
od(od == -9999 | od==-9.999) = nan;
This will not only solve the index out of bounds problem, but speed up your code quite a lot as an extra bonus.
BR/Patrik
另请参阅
类别
在 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!