summation of array elements

1 回表示 (過去 30 日間)
Terry McGinnis
Terry McGinnis 2015 年 6 月 22 日
編集済み: Azzi Abdelmalek 2015 年 6 月 22 日
I have an array of say 5 elements and I want to run a loop and find the cumulative sum till the ith iteration eg.
array if f=[1 2 3 4 5]
so in the first iteration sum should be 1,in the 2nd it should be 3,in the third it should be 6 and so on...
what is the most efficient way to do this?
thanks in advance:]

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 22 日
編集済み: Azzi Abdelmalek 2015 年 6 月 22 日
f=[1 2 3 4 5];
out=cumsum(f)
  4 件のコメント
Guillaume
Guillaume 2015 年 6 月 22 日
or just iterate over the cumsum
f = [1 2 3 4 5]
for s = cumsum(f)
%do something with s
end
Terry McGinnis
Terry McGinnis 2015 年 6 月 22 日
this is what i needed.thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by