Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
replacing NaN based on a specific moving window

Subject: replacing NaN based on a specific moving window

From: Kuo-Hsien

Date: 27 Feb, 2009 21:32:01

Message: 1 of 4

Dear all, I'm dealing with gap filling on weather measurements which the NaN should be filled based on the time window of several days.(i.e., neighborhood hour of several days).

For example, one NaN at 5pm will be replaced by the mean value in the neighborhood hour of neighborhood several days. (let's say 4, 5 and 6pm of neighborhood 5 days.)

Here is the bone of question I like to deal with:

values = rand(1,1000)';
fake_NaN = floor(rand(1,300)'*1000);
values(fake_NaN) = NaN;
for i = 1:length(values)
n = 24 * i * (1:5)
having_nan_index = find(isnan(values))
new_values = nanmean(values(having_nan_index * n-1:having_nan_index*n+1))
:
Something like that
:

If you have any solutions, advices and tips, please feel free to let me know.

Thanks, Michael

Subject: replacing NaN based on a specific moving window

From: Image Analyst

Date: 27 Feb, 2009 21:42:00

Message: 2 of 4

Kuo-Hsien, Michael
Take a look at the convolution function, conv. I'm not sure but maybe it will ignore nan's and give you the means. If it does, then just find the nan's in the original matrix and replace them with the values from the convolved matrix.
Regards,
ImageAnalyst

Subject: replacing NaN based on a specific moving window

From: Kuo-Hsien

Date: 2 Mar, 2009 19:50:17

Message: 3 of 4

Thanks for the tip, but it seems the one I want. Michael
"Image Analyst" <imageanalyst@mailinator.com> wrote in message <go9mn8$sot$1@fred.mathworks.com>...
> Kuo-Hsien, Michael
> Take a look at the convolution function, conv. I'm not sure but maybe it will ignore nan's and give you the means. If it does, then just find the nan's in the original matrix and replace them with the values from the convolved matrix.
> Regards,
> ImageAnalyst

Subject: replacing NaN based on a specific moving window

From: Kuo-Hsien

Date: 2 Mar, 2009 19:59:01

Message: 4 of 4

I'm referencing these two tips to deal with it. Thanks, Michael
1. ndnanfilter.m
http://www.mathworks.com/matlabcentral/fileexchange/20417
2. moving_average v3.1
http://www.mathworks.com/matlabcentral/fileexchange/12276

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us