Reputation: 13614
I have such a matrix
m1 = [ 1 2 3; 4 5 6; 1 2 3] m2 = [ 2 2 2];
and I want to multiply each row of m1 with m2 elementwise .
So result is
result = [2 4 6; 8 10 12; 2 4 6]
How would I do it?
Upvotes: 5
Views: 5840
Reputation: 276
You could also use
result = diag(m2)*m1;
Upvotes: 2
Reputation: 13131
bsxfun(@times,m1,m2) ans = 2 4 6 8 10 12 2 4 6
Upvotes: 15