Index in position 2 exceeds array bounds (must not exceed 1) ?

1 回表示 (過去 30 日間)
Prabhu R
Prabhu R 2021 年 9 月 6 日
コメント済み: Prabhu R 2021 年 9 月 7 日
My Code is :
function Hout = Hcomb(a , b , c)
%%%%% Get the size of Image
[r ,c] = size(a);
for i = 1:r
for j= 1:c
if (a(i,j) > b(i,j)) && (a(i,j) > c(i,j))
Hout(i,j) = a(i,j);
elseif (b(i,j) > a(i,j)) && (b(i,j) > c(i,j))
Hout(i,j) = b(i,j);
elseif (c(i,j) > a(i,j)) && (c(i,j) > b(i,j))
Hout(i,j) = c(i,j);
end
end
end
return;
  1 件のコメント
Prabhu R
Prabhu R 2021 年 9 月 6 日
Error at elseif (c(i,j) > a(i,j)) && (c(i,j) > b(i,j))

サインインしてコメントする。

採用された回答

Simon Chan
Simon Chan 2021 年 9 月 6 日
One of the input argument is variable 'c' and you use the same name again for the size of variable 'a' and hence gives you an error, try rename them as follows:
function Hout = Hcomb(a , b , c)
%%%%% Get the size of Image
[row ,col] = size(a);
for i = 1:row
for j= 1:col
if (a(i,j) > b(i,j)) && (a(i,j) > c(i,j))
Hout(i,j) = a(i,j);
elseif (b(i,j) > a(i,j)) && (b(i,j) > c(i,j))
Hout(i,j) = b(i,j);
elseif (c(i,j) > a(i,j)) && (c(i,j) > b(i,j))
Hout(i,j) = c(i,j);
end
end
end
return;
  1 件のコメント
Prabhu R
Prabhu R 2021 年 9 月 7 日
works good i forget about variable name

サインインしてコメントする。

その他の回答 (1 件)

DGM
DGM 2021 年 9 月 6 日
編集済み: DGM 2021 年 9 月 6 日
Nothing in this code guarantees that the size of b and c are identical to the size of a. If they aren't the same size, you will end up with errors. Since you didn't reveal anything about what you passed, I'm going to have to assume that's what you did.

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by