Index in position 1 exceeds array bounds (must not exceed 64) in digital image data.
Show older comments
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);
Answers (1)
Walter Roberson
on 31 Jan 2019
0 votes
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 Comments
Madan Kumar
on 1 Feb 2019
Walter Roberson
on 1 Feb 2019
You have not defined the answer you want in that situation.
Your comments in the code about the dimensions of the variables are useful, but you could use some additional documentation about the rest of it, such as what it is that the code is intended to compute. I sort of vaguely understand what it is doing, but the ideas that come to mind do not make much sense without a corresponding calculation of max() to extract sub-volumes.
Madan Kumar
on 1 Feb 2019
Walter Roberson
on 1 Feb 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.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!