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;

채택된 답변

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개)

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 CenterFile Exchange에서 Matched 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