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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by