Compare elements from two matrix.
Show older comments
Hi!
I want to compare elements for two matrix and then create another matrix with maximal element (comparing abs(x1) i abs(x2), not x1 i x2).
I wrote this:
But maybe it's possible to do it quicker and more efficient?
for i = 1:numel(x1)
if (abs(x1(i)) > abs(x2(i)))
x(i) = x2(i);
else
x(i) = x1(i);
end
end
Accepted Answer
More Answers (1)
Olawale Ikuyajolu
on 13 May 2020
new_matrix = max(abs(x1),abs(x2);
Categories
Find more on Startup and Shutdown 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!