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

Home » Public Forums » archive » Fill Missing values with NaN
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
Fill Missing values with NaN [message #94666] Thu, 10 August 2017 12:00 Go to next message
idlusr is currently offline  idlusr
Messages: 2
Registered: August 2017
Junior Member
How can one do the following in IDL:

time = [1, 4, 7, 8]
dens =[80,60,30,50]

alltimes = [0,1,2,3,4,5,6,7,8,9]
densnew = [NaN, 80, NaN, NaN, 60, NaN, NaN, 30, 50, NaN]

i.e., compare time to all times, allowing densnew to have same # of elements as all times but ONLY the densities in dens. Missing elements in densnew (depending on time) are given NaN value.

Thank you!
Re: Fill Missing values with NaN [message #94667 is a reply to message #94666] Thu, 10 August 2017 12:03 Go to previous messageGo to next message
idlusr is currently offline  idlusr
Messages: 2
Registered: August 2017
Junior Member
On Thursday, August 10, 2017 at 12:00:41 PM UTC-7, idlusr wrote:
> How can one do the following in IDL:
>
> time = [1, 4, 7, 8]
> dens =[80,60,30,50]
>
> alltimes = [0,1,2,3,4,5,6,7,8,9]
> densnew = [NaN, 80, NaN, NaN, 60, NaN, NaN, 30, 50, NaN]
>
> i.e., compare time to all times, allowing densnew to have same # of elements as all times but ONLY the densities in dens. Missing elements in densnew (depending on time) are given NaN value.
>
> Thank you!

Forgot to mention, the values in my data set are type double for time & float for density. Thanks again!
Re: Fill Missing values with NaN [message #94670 is a reply to message #94666] Thu, 10 August 2017 23:51 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
I don't get the question. So I will just suggest the use of the function finite() to check for not-NaN values in densnew. This will give you the valid indices.

valInd = finite(densnew)

times_fromAlltimes = alltimes[valInd]
dens_fromDensnew = densnew[valInd]

Hope it helps.
Helder
Re: Fill Missing values with NaN [message #94672 is a reply to message #94666] Fri, 11 August 2017 05:31 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
The example below works well with integer times. For floats, you should define "alltimes" as the beginning of the sampling interval and "times" as the center of the sampling interval. This is in-part because of how Value_Locate works and in-part because of the discreteness of floating point values.

;Time Arrays
time = [1, 4, 7, 8]
alltimes = IndGen(10)

;Data Arrays
dens = [80, 60, 30, 50]
densnew = Replicate( !Values.D_NaN, N_Elements(alltimes) )

;Locate "time" within "alltimes"
iTime = Value_Locate(alltimes, time)

;Fill the new density array
densnew[iTime] = dens

;Result
print, densnew, FORMAT='(10(f5.2, 2x))'
NaN 80.00 NaN NaN 60.00 NaN NaN 30.00 50.00 NaN
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: plot solid circle on image
Next Topic: IDL LSODE double precision

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

Current Time: Wed Oct 08 07:23:52 PDT 2025

Total time taken to generate the page: 0.00633 seconds