How to remove for-loop in computing a vector of sums?
1 回表示 (過去 30 日間)
古いコメントを表示
How to compute rcross vector without the for-loop?
rcross = zeros( length(elementProduct) - prefixLen , 1 );
for ii = 1: length(elementProduct) - prefixLen
rcross(ii) = sum( elementProduct(ii : ii + prefixLen - 1) );
end
In one scenario prefixLen is 8. length(elementProduct) can vary from a few hundred to a few million.
6 件のコメント
Paul Hoffrichter
2020 年 12 月 8 日
@KSSV,
Thank you for your comment. If you move it to an answer, I will accept it. Thanks again!
~Paul
Paul Hoffrichter
2020 年 12 月 8 日
I think your approach will also work. But I believe (without testing) that using conv would be slower than movsum.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Instrument Control Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!