フィルターのクリア

Index exceed matrix dimensions.

7 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by