How to fix index in position 2 exceeds array bounds (must not exceed 1920)

2 views (last 30 days)
The error I receive is :
Index in position 2 exceeds array bounds. Index must not exceed 1920.
Error in firstpass (line 46)
if IN(jj+N/2,ii+M/2)~=1
My code:
function [xx,yy,datax,datay]=firstpass(A,B,N,ol,counter,idx,idy,maske)
% function [x,y,datax,datay]=firstpass(A,B,M,N,ol,counter,idx,idy,maske)
%
% This function is used in conjunction with the MULTIPASS.M run-file.
% Inputs are allocated from within MULTIPASS.
% 1999 - 2001, J. Kristian Sveen (jks@math.uio.no)
% For use with MatPIV 1.5, Copyright
% Distributed under the terms of the GNU - GPL license
% timestamp: 21.20, 20 Feb 2001
if length(N)==1
M=N;winsize=[M N];
elseif length(N)==2
M=N(1); N=N(2); winsize=[M N];
end
overlap=ol; [sy,sx]=size(A);
if nargin < 6 | isempty(idx) | isempty(idy)
idx=zeros(floor(sy/(N*(1-ol))),floor(sx/(M*(1-ol))));
idy=zeros(floor(sy/(N*(1-ol))),floor(sx/(M*(1-ol))));
end
x=zeros(ceil((size(A,1)-N)/((1-overlap)*N))+1, ...
ceil((size(A,2)-M)/((1-overlap)*M)) +1);
y=x; u=x; v=x;
% change . october 2001, weight matrix added.
% W=weight('cosn',[M N],100);
if nargin==8,
if ~isempty(maske)
IN=zeros(size(maske(1).msk));
for i=1:length(maske)
IN=IN+double(maske(i).msk);
end
else
IN=zeros(size(A));
end,
elseif nargin<8
IN=zeros(size(A));
end
cj=1;tic
for jj=1:((1-ol)*N):sy-N+1
ci=1;
for ii=1:((1-ol)*M):sx-M+1
if IN(jj+N/2,ii+M/2)~=1
  2 Comments
the cyclist
the cyclist on 29 Jul 2022
It's pretty difficult for us to diagnose this without knowing the values of the input parameters that results in the error. Can you tell us how you called the function, or upload a MAT file with the parameters?
You should also be able to figure this out yourself by setting a breakpoint at line 46 (right before the error), and seeing if all the values are what you expect.
Kelsey O'Donnell
Kelsey O'Donnell on 29 Jul 2022
It is a part of my runpiv code which is part of MatPIV, a code for running particle image velocimetry analysis. The code is attached. I first define my world coordinates with a scale image then create a mask for the images I want to process over areas that should be ignored by the processer.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 30 Jul 2022
The error message indicates that you are trying to index your variable using a value that exceeds the size of the array. Here, position 2 means the value you are using to index the columns of IN. Specifically, there are 1920 columns, and the value your code is returning for ii+M/2 is >1920.
For example:
A = 1:5; % variable with 1 row, 5 columns
% This works
A(1,3)
ans = 3
% This generates the same error message you are getting
A(1,6)
Index in position 2 exceeds array bounds. Index must not exceed 5.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!