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

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com