help-octave
[Top][All Lists]
Advanced

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

Re: vectorized moving average?


From: James Sherman Jr.
Subject: Re: vectorized moving average?
Date: Fri, 7 May 2010 15:58:16 -0400

I'm not sure what you mean by weighting of 0.5, but to do a simple 10-day average, it'd be

x = rand(1, 100);
y = filter(1/10*ones(1, 10), 1, x)

This assumes that the values at negative time (x(0), x(-1), etc) are all zero.  So, for example, the first value of y would be x(1)/10.

On Fri, May 7, 2010 at 3:33 PM, Tim Rueth <address@hidden> wrote:
I looked at both conv() and filter(), but can't figure out how to do a
moving average with them.  Perhaps I'm not understanding the functions of
the input vars correctly.

Let's say I have an array, a = rand(1,100).  Can you tell me how I'd use
conv() and filter() to take, say the 10-day moving average of it, with a
weighting of 0.5?

Thanks!


> -----Original Message-----
> From: Andy Buckle [mailto:address@hidden]
> Sent: Thursday, May 06, 2010 12:06 AM
> To: address@hidden
> Cc: address@hidden
> Subject: Re: vectorized moving average?
>
> conv is also an m file, but it only has a few ifs in. then it
> calls filter to get the job done. which is an oct file.
>
> Andy
>
> On Thu, May 6, 2010 at 6:28 AM, Tim Rueth <address@hidden> wrote:
> > Does anyone know how to take an n-day weighted moving average of a
> > vector without using a for-loop?  I looked at the M code
> for movavg()
> > and it uses a for-loop, so I'm guessing there probably isn't a way,
> > but I thought I'd check.  Thanks.
> >
> > --Tim
> > _______________________________________________
> > Help-octave mailing list
> > address@hidden
> > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> >
> >
>
>
>
> --
> /* andy buckle */
>


_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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