Vectorization of product of flipped vectors

1 回表示 (過去 30 日間)
Tétef
Tétef 2013 年 2 月 22 日
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.

採用された回答

Teja Muppirala
Teja Muppirala 2013 年 2 月 22 日
Faster for long vectors, slower for short ones:
r = conv(r1,r2);
r = r(1:numel(r1));
  1 件のコメント
Tétef
Tétef 2013 年 2 月 22 日
thx !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by