Vector Matrix multiplication (Row wise)

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 日

1 投票

L = L.*repmat(V, [1 N]);

その他の回答 (3 件)

Vladimir Kazei
Vladimir Kazei 2017 年 10 月 9 日
編集済み: Vladimir Kazei 2017 年 10 月 9 日

2 投票

L = L .* V;
seif seif
seif seif 2018 年 1 月 26 日
編集済み: seif seif 2018 年 1 月 26 日

1 投票

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

2 件のコメント

Noah Tang
Noah Tang 2019 年 10 月 28 日
Could you explain that why does this indexing trick work?
Sanders
Sanders 2024 年 12 月 17 日
Vladimir Kazei's version was significantly faster on my computer.

サインインしてコメントする。

James Tursa
James Tursa 2015 年 9 月 16 日

0 投票

L = bsxfun(@times,L,V);

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 9 月 16 日

コメント済み:

2024 年 12 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by