Replacing values in matrix that are greater than another matrix
Mostrar comentarios más antiguos
I have the following code that, if a value in A is greater than a corresponding value in B, will replace that value with the value in B, returning the result as C.
How could I rewrite this without loops? Thanks in advance.
C=[];
[m n] = size(A);
for i = 1:m
for j = 1:n
if A(i, j) < B(i, j)
C(i, j) = A(i, j);
else
C(i, j) = B(i, j);
end
end
end
disp(C);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!