comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Cumulative sum
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Cumulative sum [message #33706] Thu, 16 January 2003 15:01
graves is currently offline  graves
Messages: 7
Registered: September 2001
Junior Member
> Is there a function for computing the cumulative sum of
> an array (similar to matlab's cumsum)?
> For instance: cumsum(indgen(5)) = [1,3,6,10,15]

The IDL equivalent is to use the total function with the cumulative
keyword, so your example would be total(indgen(5), /cumulative).





Ted
Re: Cumulative sum [message #33709 is a reply to message #33706] Thu, 16 January 2003 13:26 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
rkj@dukebar.crml.uab.edu (R. Kyle Justice) writes:


> Thanks for the quick replies. However, I am using
> PV-Wave and the TOTAL function does not have a
> Cumulative keyword. I guess I will be looping . . .

Yes, and it's a fairly new keyword even in IDL. This is one area
where I have resorted to looping unfortunately.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Cumulative sum [message #33710 is a reply to message #33709] Thu, 16 January 2003 12:33 Go to previous message
rkj is currently offline  rkj
Messages: 66
Registered: February 1996
Member
Thanks for the quick replies. However, I am using
PV-Wave and the TOTAL function does not have a
Cumulative keyword. I guess I will be looping . . .


Kyle
Re: Cumulative sum [message #33711 is a reply to message #33710] Thu, 16 January 2003 12:14 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
"R. Kyle Justice" <rkj@dukebar.crml.uab.edu> wrote in message
news:b072o8$6j0$1@SonOfMaze.dpo.uab.edu...
> Is there a function for computing the cumulative sum of
> an array (similar to matlab's cumsum)?
>
> For instance: cumsum(indgen(5)) = [1,3,6,10,15]
>
> Kyle J.

See the CUMULATIVE keyword for the TOTAL function:

"If this keyword is set, the result is an array of the same size as the
input, with each element, i, containing the sum of the input array elements
0 to i. This keyword also works with the Dimension parameter, in which case
the sum is performed over the given dimension."

Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/
Re: Cumulative sum [message #33712 is a reply to message #33711] Thu, 16 January 2003 12:14 Go to previous message
mchinand is currently offline  mchinand
Messages: 66
Registered: September 1996
Member
In article <b072o8$6j0$1@SonOfMaze.dpo.uab.edu>,
R. Kyle Justice <rkj@dukebar.crml.uab.edu> wrote:
> Is there a function for computing the cumulative sum of
> an array (similar to matlab's cumsum)?
>
> For instance: cumsum(indgen(5)) = [1,3,6,10,15]
>
> Kyle J.
>
>

Yes, use the /CUMULATIVE keyword to TOTAL. With the optional DIMENSION
argument can set over which dimension is summed over.

--Mike


--
Michael Chinander
m-chinander@uchicago.edu
Department of Radiology
University of Chicago
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Push value onto an array?
Next Topic: plotting particle data with halos?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:26:35 PDT 2025

Total time taken to generate the page: 0.00571 seconds