Vector Matrix multiplication (Row wise)

139 次查看(过去 30 天)
Hi, I need to multiply each row of very large matrix with a row of corresponding vector. I don't really want to use for loop for that, i.e.,
N=15000;
L=rand(N,N); V=rand(N,1);
for i=1:1:N
L(i,:)=V(i)*L(i,:);
end
is it possible to do this in vectorized way?
Thank you
Erdem

采纳的回答

Thorsten
Thorsten 2015-9-16
L = L.*repmat(V, [1 N]);

更多回答(3 个)

Vladimir Kazei
Vladimir Kazei 2017-10-9
编辑:Vladimir Kazei 2017-10-9
L = L .* V;

seif seif
seif seif 2018-1-26
编辑:seif seif 2018-1-26
I'd suggest a faster version than the above methods:
L = L .* v(:, ones(N,1));

James Tursa
James Tursa 2015-9-16
L = bsxfun(@times,L,V);

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by