MATLAB Answers

multiply vector and matrix

7 views (last 30 days)
Ido Gross
Ido Gross on 12 Aug 2020
Edited: madhan ravi on 12 Aug 2020
Hi!
I have a matrix such as:
a = [1 1 1]
[2 2 2]
[3 3 3]
and a vector:
b = [2]
[2]
[2]
I want to multiply them so i'll get:
a*b = [2 2 2]
[4 4 4]
[6 6 6]
How can I do it in matlab?
thanks!

  0 Comments

Sign in to comment.

Answers (3)

madhan ravi
madhan ravi on 12 Aug 2020
a .* b

  0 Comments

Sign in to comment.


madhan ravi
madhan ravi on 12 Aug 2020
Wanted = cellfun(@times, a, b, 'un', 0);
celldisp(Wanted)

  0 Comments

Sign in to comment.


madhan ravi
madhan ravi on 12 Aug 2020
Edited: madhan ravi on 12 Aug 2020
Wanted = cell2mat(a) .* cell2mat(b);
celldisp(num2cell(Wanted, 2))

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by