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

1 visualización (últimos 30 días)
Prabhu R
Prabhu R el 6 de Sept. de 2021
Comentada: Prabhu R el 7 de Sept. de 2021
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;

Respuesta aceptada

Simon Chan
Simon Chan el 6 de Sept. de 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;

Más respuestas (1)

DGM
DGM el 6 de Sept. de 2021
Editada: DGM el 6 de Sept. de 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.

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by