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?
bsxfun(@times,m1,m2)
ans =
2 4 6
8 10 12
2 4 6
You could also use
result = diag(m2)*m1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With