help-octave
[Top][All Lists]
Advanced

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

Re: vectorized moving average?


From: Jaroslav Hajek
Subject: Re: vectorized moving average?
Date: Thu, 6 May 2010 13:08:25 +0200

On Thu, May 6, 2010 at 12:45 PM, Fredrik Lingvall <address@hidden> wrote:
>
>
> On Thu, May 6, 2010 at 11:40 AM, Francesco Potortì <address@hidden>
> wrote:
>>
>> >Does anyone know how to take an n-day weighted moving average of a vector
>> >without using a for-loop?
>>
>> Use the filter function.
>
> Or fftconv
>

Or, for unweighted moving average, probably the fastest way is to
compute differences of a cumulative sum:

y = cumsum (x);
n = rows (x);
avg = (y(k+1:n) - y(1:n-k+1)) / k;

unfortunately, this way is also probably the most inaccurate one :)


-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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