Multiply Each Row of a 12x4 matrix by a 1x4 matrix?

1 view (last 30 days)
I imported my data file and now I am trying to multiply each row of it by a 1x4 matrix. Is this possible?

Answers (1)

Star Strider
Star Strider on 21 Apr 2015
If you want to do element-wise multiplication, bsxfun to the rescue!
See if this does what you want:
M = randi(2, 12, 4); % Create Data: Matrix
V = 1:4; % Create Data: Vector
P = bsxfun(@times, M, V); % Multiply

Categories

Find more on Matrices and 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!