Multiplication between two matrices with different number of rows

Dear all,
I have two matrices:
A=[42x5];
B=[32x1];
I want to multiply each row of B to each of A.
Kind help needed. Thank you.

2 Comments

@DV: please show us the size of the expected output array.
Expected to be: C=[42x32x5];
Thanks!

Sign in to comment.

 Accepted Answer

C = permute(A,[1,3,2]) .* reshape(B,1,[])

2 Comments

Testing:
A = rand(42,5);
B = rand(32,1);
C = permute(A,[1,3,2]) .* reshape(B,1,[]);
size(C)
ans = 1×3
42 32 5

Sign in to comment.

More Answers (0)

Asked:

DV
on 11 Jul 2022

Commented:

DV
on 11 Jul 2022

Community Treasure Hunt

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

Start Hunting!