How to multiply a vector with each column of a matrix
6 views (last 30 days)
Show older comments
Say I have a column matrix [1;2;3;4].
I have another matrix of order 3*4. Say the matrix is [1 4 7 10; 2 5 8 11; 3 6 9 12].
I want to get the result as [1 8 21 40; 2 10 24 44; 3 12 27 48].
So the each column of the 3*4 matrix should be multiplied by each elemnt of the column matrix one by one.
0 Comments
Accepted Answer
Torsten
on 29 Nov 2018
A = [1 4 7 10; 2 5 8 11; 3 6 9 12];
b = [1;2;3;4];
C = bsxfun(@times,A,b.')
1 Comment
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays 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!