Summing elements of a vector sequentially?

Is there a function that will sum a vector in the following way?
Let x be a 1 x N vector. The ith element of the output vector should be sum(x(1:i)), where i ranges from 1 to N.
I will use a for loop, if I must...
x = 1:100;
output = zeros(1,length(x))
for i = 1:length(x), output(i) = sum(x(1:i)); end
Thanks!

 채택된 답변

per isakson
per isakson 2015년 5월 31일

0 개 추천

See cumsum

댓글 수: 1

James
James 2015년 5월 31일
I had a feeling there would be a function dedicated to this. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

태그

질문:

2015년 5월 31일

댓글:

2015년 5월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by