Index exceed matrix dimensions.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Chandrasekhar
am 10 Mär. 2014
index is trying to access the matrix element which doesnt exist. index > length(array/matrix)
Antworten (1)
Patrik Ek
am 10 Mär. 2014
Bearbeitet: Patrik Ek
am 10 Mär. 2014
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
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!