필터 지우기
필터 지우기

vector matrix multiplication single row

조회 수: 1 (최근 30일)
PK
PK 2012년 10월 23일
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

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 10월 23일
a = rand(1,10);
b = rand(10,100);
out = bsxfun(@times,a.',b);

Jan
Jan 2012년 10월 23일
편집: Jan 2012년 10월 23일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by