Replacing values in matrix that are greater than another matrix
5 views (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!