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

1 visualizzazione (ultimi 30 giorni)
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;

Risposta accettata

Simon Chan
Simon Chan il 6 Set 2021
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;

Più risposte (1)

DGM
DGM il 6 Set 2021
Modificato: DGM il 6 Set 2021
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.

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by