Index exceed matrix dimensions.

조회 수: 1 (최근 30일)
SUDIPTA GHOSH
SUDIPTA GHOSH 2014년 3월 10일
편집: Patrik Ek 2014년 3월 13일
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
Chandrasekhar 2014년 3월 10일
index is trying to access the matrix element which doesnt exist. index > length(array/matrix)

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

답변 (1개)

Patrik Ek
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
  댓글 수: 1
Patrik Ek
Patrik Ek 2014년 3월 13일
편집: Patrik Ek 2014년 3월 13일
If you is still in to doing loops I would then suggest
od = od(:);
% do operations
od = reshape(od,len_a,len_b,...)
Since matlab works absolutely best for columns.

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

카테고리

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