summation of array elements

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by