comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: replacing "NAN" values using interpolation in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: replacing "NAN" values using interpolation in IDL [message #82782] Thu, 17 January 2013 07:05 Go to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On 1/17/13 4:02 AM, idlhelp wrote:
> Dear all, I have an data array. I have many "NaN" values. I want to replace those "NaN" values by the nearby values either using interpolation. Is there any way to do that in IDL.
>
> Thanks in advance
>

Yes, there is.

Oh, you want to know how? ;-)

I would do something like this, if I had an array of locations x and a
data array data:

; sample data
x = [1., 2., 3., 5., 7., 7.5, 9., 12., 12.1]
data = [0., !values.f_nan, 10., 15., !values.f_nan, !values.f_nan, 5.,
4., 5.]

; figure out where there are NaNs and where the useful data are
gooddata = where(data eq data, ngooddata, $
comp=baddata, ncomp=nbaddata)

; interpolate at the locations of the bad data using the good data
if nbaddata gt 0 then begin
data[baddata] = interpol(data[gooddata], x[gooddata], x[baddata])
endif

-Jeremy.
Re: replacing "NAN" values using interpolation in IDL [message #82974 is a reply to message #82782] Mon, 28 January 2013 09:27 Go to previous message
abc is currently offline  abc
Messages: 46
Registered: March 2011
Member
On Thursday, January 17, 2013 4:05:11 PM UTC+1, Jeremy Bailin wrote:
> On 1/17/13 4:02 AM, idlhelp wrote:
>
>> Dear all, I have an data array. I have many "NaN" values. I want to replace those "NaN" values by the nearby values either using interpolation. Is there any way to do that in IDL.
>
>>
>
>> Thanks in advance
>
>>
>
>
>
> Yes, there is.
>
>
>
> Oh, you want to know how? ;-)
>
>
>
> I would do something like this, if I had an array of locations x and a
>
> data array data:
>
>
>
> ; sample data
>
> x = [1., 2., 3., 5., 7., 7.5, 9., 12., 12.1]
>
> data = [0., !values.f_nan, 10., 15., !values.f_nan, !values.f_nan, 5.,
>
> 4., 5.]
>
>
>
> ; figure out where there are NaNs and where the useful data are
>
> gooddata = where(data eq data, ngooddata, $
>
> comp=baddata, ncomp=nbaddata)
>
>
>
> ; interpolate at the locations of the bad data using the good data
>
> if nbaddata gt 0 then begin
>
> data[baddata] = interpol(data[gooddata], x[gooddata], x[baddata])
>
> endif
>
>
>
> -Jeremy.

Thanks Jeremy, but the problem I am having is that I don't have any sample data 'x'. I have only 'data' and want to use that 'data' file again for interpolating and replacing the NaN value. Any Idea how to do that.
thanks
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Help with rgb_table in plot
Next Topic: Help with vert_colors and rgb_table

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:11:20 PDT 2025

Total time taken to generate the page: 0.00456 seconds