column vector dot multiplied with a row vector. Multiple such operations..

I have a 5000x10, and another 5000x20 matrix. I want to dot multiply 5000 of each corresponding 10x1 & 1x20 vectors.
I want to get back 5000 of this operation. (10,1) .* (1,20) ==> (10x20). Thus into a (5000,10,20) matrix.
I can go into a loop for 5000 times. But is there a quicker mechanism in Matlab?
Thanks.

 Accepted Answer

See
Or what about:
a = rand(5000, 10);
b = rand(5000, 20);
c = a .* reshape(b, [5000, 1, 20]); % >= Matlab R2016b
For older Matlab versions:
c = bsxfun(@times, a, reshape(b, [5000, 1, 20]));
Quicker would be to avoid the artificial inflate of the arrays: The resulting dyadic products are very redundant. Better reformulate the mathematical expressions such, that the single vectors are used.

More Answers (0)

Categories

Asked:

LW
on 3 Feb 2018

Commented:

LW
on 4 Feb 2018

Community Treasure Hunt

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

Start Hunting!