vectorB(n) = sum(vectorA(1:n)) without a loop
1 回表示 (過去 30 日間)
古いコメントを表示
I would like to do:
vectorB(n) = sum(vectorA(1:n))
without a loop.
Thanks in advance
0 件のコメント
採用された回答
madhan ravi
2019 年 9 月 2 日
編集済み: madhan ravi
2019 年 9 月 2 日
Perhaps you just want cumsum()
help cumsum
doc cumsum
Or you just need:
v= accumarray(n(:),n(:),[],@(x) sum(vectorA(1:x)));
Wanted = v(n);
% or
Wanted = arrayfun(@(x) sum(vectorA(1:x)),n)
その他の回答 (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!