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

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