Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

vector matrix multiplication single row

Asked by PK on 23 Oct 2012

is there a chance to multiply this way rand(1,10)*rand(10,100) but the way of calculation is each singe element of 1x10 mtx should multiply entire row of 10x100 mtx

0 Comments

PK

Products

No products are associated with this question.

2 Answers

Answer by Andrei Bobrov on 23 Oct 2012
a = rand(1,10);
b = rand(10,100);
out = bsxfun(@times,a.',b); 

0 Comments

Andrei Bobrov
Answer by Jan Simon on 23 Oct 2012
Edited by Jan Simon on 23 Oct 2012

While I'd prefer BSXFUN as Andrei has posted already, there is an alternative:

a = rand(10,1);   % Transposed!
b = rand(10,100);
R = a(:, ones(1, 100)) .* b;

Time measurements seems like the ONES is not created explicitely, such that this is more efficient than it looks like.

0 Comments

Jan Simon

Contact us