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

3 次查看(过去 30 天)
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?

采纳的回答

James Tursa
James Tursa 2020-11-24
编辑:James Tursa 2020-11-24
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by