Vectorization of product of flipped vectors
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Teja Muppirala
2013년 2월 22일
Faster for long vectors, slower for short ones:
r = conv(r1,r2);
r = r(1:numel(r1));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!