How to take the bigger of two corresponding elements, each from a vector
In Matlab, suppose there are two vectors v1 an开发者_如何学编程d v2 of the same length. I wonder how to form a new vector w of the same length, with w(i)=max(v1(i), v2(i)) quickly? Thanks and regards!
How about doing
w = max(v1, v2)
octave:2> v1 = [1, 2, 3]
v1 =
1 2 3
octave:3> v2 = [5, 1, 7]
v2 =
5 1 7
octave:4> w = max(v1, v2)
w =
5 2 7
How about
v1 = (rand(1,5) * 100)';
v2 = (rand(1,5) * 100)';
w = max(v1,v2);
精彩评论