help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cumulative mean


From: Francesco Potortì
Subject: Re: Cumulative mean
Date: Fri, 21 May 2010 12:41:12 +0200

>Looking for something like cummax and cummin , is there a function to
>calculate the cumulative mean of a matrix / vector? I know it's an easy
>program to implement and I already made it on my own (as you may see in the
>attached file) , I just wanna know if there is a standard Octave function,
>which will be probably faster than mine.

I think that this is what you want:

octave> A=magic(4);A=horzcat(A,2*A)
A =

   16    2    3   13   32    4    6   26
    5   11   10    8   10   22   20   16
    9    7    6   12   18   14   12   24
    4   14   15    1    8   28   30    2

octave> cumsum(A)
ans =

   16    2    3   13   32    4    6   26
   21   13   13   21   42   26   26   42
   30   20   19   33   60   40   38   66
   34   34   34   34   68   68   68   68

octave> diag(1./(1:rows(A)))*cumsum(A)
ans =

   16.0000    2.0000    3.0000   13.0000   32.0000    4.0000    6.0000   26.0000
   10.5000    6.5000    6.5000   10.5000   21.0000   13.0000   13.0000   21.0000
   10.0000    6.6667    6.3333   11.0000   20.0000   13.3333   12.6667   22.0000
    8.5000    8.5000    8.5000    8.5000   17.0000   17.0000   17.0000   17.0000

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]