Vectorization of product of flipped vectors

3 vues (au cours des 30 derniers jours)
Tétef
Tétef le 22 Fév 2013
I'm looking for how to vectorize this loop :
r=zeros(1,length(r1));
for i=1:length(r1);
r(i)=sum(r1(1:i).*r2(i:-1:1));
end
r1 and r2 are two vectors of the same size.

Réponse acceptée

Teja Muppirala
Teja Muppirala le 22 Fév 2013
Faster for long vectors, slower for short ones:
r = conv(r1,r2);
r = r(1:numel(r1));

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by