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.

 Respuesta aceptada

Jan
Jan el 4 de Feb. de 2018
Editada: Jan el 4 de Feb. de 2018
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.

Más respuestas (0)

Categorías

Más información sobre Statics and Dynamics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

LW
el 3 de Feb. de 2018

Comentada:

LW
el 4 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by