For Programmers: Free Programming Magazines  


Home > Archive > Matlab > August 2005 > cumulative sum of a vector









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cumulative sum of a vector
Jorge Sing

2005-08-31, 7:01 pm

i am looking for a function that will take a vector and make another
vector that is a cumulative sum of the elements of the first one.
Like:
M=[1 2 3 3 2 1]
then the cumulative sum would be:
cum_sum_M=[1 3 6 9 11 12]

i have several vectors of around 100 elements each to work on...
thank you.
PB

2005-08-31, 7:01 pm

Jorge Sing wrote:
>
>
> i am looking for a function that will take a vector and make
> another
> vector that is a cumulative sum of the elements of the first one.
> Like:
> M=[1 2 3 3 2 1]
> then the cumulative sum would be:
> cum_sum_M=[1 3 6 9 11 12]
>
> i have several vectors of around 100 elements each to work on...
> thank you.


Guess what? The function is called cumsum. Take a look at the
lookfor() function of matlab, it is really useful, see:

help lookfor

HTH

PB
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com