Index in position 1 exceeds array bounds (must not exceed 64) in digital image data.

2 vues (au cours des 30 derniers jours)
Madan Kumar
Madan Kumar le 31 Jan 2019
Commenté : Walter Roberson le 1 Fév 2019
It is part of a big code to work with digital image data from satellite observation. It shows error "Index in position 1 exceeds array bounds (must not exceed 64)" in the calculation of intensity; Int(7,:),Int(8,:) and Int(9,:). I know this is related to the dimension of nx (some elements are 64 and all elements of ny are less than 60), but unable to solve it. Someone might have experienced similar problem but I didn't find one reported related to digital image data. Can anyone please help. Thank you. I am working in Matlab R2018a.
Nim=length(Time);
for i=1:Nim,
ds=sqrt((x0(i)-x(:,:,i)).^2+(y0(i)-y(:,:,i)).^2); %xo, y0 have dimensions (1x750), x and y have dimensions (64x64x750).
[ar,nr]=min(ds);
[ac,nc]=min(ar);
nx(i)=nc; %dimension of nx is 1x750.
ny(i)=nr(nc); %dimension of ny is 1x750.
end
I(1,:)=mean(mean(image(nx-1,ny+1,:),1),2);
I(2,:)=mean(mean(image(nx-1,ny,:),1),2);
I(3,:)=mean(mean(image(nx-1,ny-1,:),1),2);
I(4,:)=mean(mean(image(nx,ny+1,:),1),2);
I(5,:)=mean(mean(image(nx,ny,:),1),2);
I(6,:)=mean(mean(image(nx,ny-1,:),1),2);
I(7,:)=mean(mean(image(nx+1,ny+1,:),1),2);
I(8,:)=mean(mean(image(nx+1,ny,:),1),2);
I(9,:)=mean(mean(image(nx+1,ny-1,:),1),2);

Réponses (1)

Walter Roberson
Walter Roberson le 31 Jan 2019
There is some plane for which the smallest value is in the last column, 64, so some nx entry is 64. Your I 7 computation adds 1 to nx getting a 65 which you try to use as an index .
You were just unlucky that none of the minima were in column 1 or else you would have caught the problem with the first I 1 calculation .
  4 commentaires
Madan Kumar
Madan Kumar le 1 Fév 2019
I just want to calculate the intensity, I, from the above code.
Walter Roberson
Walter Roberson le 1 Fév 2019
Then your existing code is fine. You existing code does exactly what it is supposed to do for the mathematics you have defined -- which is to say that your existing code will fail sometimes, just like the mathematics will fail sometimes.
If you do not want your code to fail for those situations, then define different mathematics .
For example:
Rule:
"find the plus sign. Average the number before and after it"
Input:
--3/5------4+8--9*
Output: well defined 6
Input:
+8--9*--3/5------
Output: crash because there is no number before the plus sign. Crash is the correct output for this situation.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by