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

 Réponse acceptée

Plus de réponses (3)

seif seif
seif seif le 26 Jan 2018
Modifié(e) : seif seif le 26 Jan 2018
I'd suggest a faster version than the above methods:
L = L .* v(:, ones(N,1));

2 commentaires

Noah Tang
Noah Tang le 28 Oct 2019
Could you explain that why does this indexing trick work?
Sanders
Sanders le 17 Déc 2024
Vladimir Kazei's version was significantly faster on my computer.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by