Index in position 1 is invalid. Array indices must be positive integers or logical values.

3 views (last 30 days)
kernel = [0 1 0; 1 0 1; 0 1 0]
A = [10 2 10; 10 5 3; 4 2 5]
m = 3;
n = 3;
for i=1:m
for j=1:n
sum = (kernel(m-i,n-j) * A(i-1,j-1))
end
end
Hi everybody,
I got this error ;
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in file (line 22)
t = A(x1,x2);
Why I got this error?

Accepted Answer

James Tursa
James Tursa on 24 Nov 2020
Edited: James Tursa on 24 Nov 2020
When i=m in your loop you try to access kernel(m-m,n-j) which is kernel(0,m-j), and 0 is an invalid index. Similar problems with all of the other indexing on this line. It is easy to find values of the for-loop indices where each index in your computation is invalid.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!