help-octave
[Top][All Lists]
Advanced

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

Re: moving average with nan data


From: James Sherman Jr.
Subject: Re: moving average with nan data
Date: Tue, 18 May 2010 23:42:33 -0400

I think it depends on what behavior you want.  If you want to, say repeat the last value in the sequence when you get a nan, you could do something like:

nan_indices = isnan(data);
data(nan_indices) = data(nan_indices-1);
filtered_data = filter(b,1,data);

then you could use the filter command as have there.  If you want to just completely ignore them and replace them afterwards, you could do something like:
new_data = data(~nan_indices);
filtered_data = filter(b,1,new_data);
new_filtered_data(~nan_indices) = filtered_data;
new_filtered_data(nan_indices) = NaN;

But, these are just some attempts at getting around putting NaN's into the filter function itself.  If this isn't what you want, something more involved might be needed.

On Tue, May 18, 2010 at 8:23 PM, febty febriani <address@hidden> wrote:
Hi everyone,

If I have data like below
1
2
3
nan
3
4
5
nan
8
9

How can I do the three points moving average of data?
I tried to use :

b=ones(1,3)/3;
y=filter(b,1,x);

but, it didn't work.
any help is appreciated.

--

******
febty febriani
Indonesian Institute of Sciences
Research Center for Physics
Kompleks PUSPIPTEK
Serpong, Indonesia, 15314

_______________________________________________
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]