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

Home » Public Forums » archive » Re: Assign data point to n-Dimensional grid
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Assign data point to n-Dimensional grid [message #80593 is a reply to message #80592] Fri, 22 June 2012 10:49 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Friday, June 22, 2012 12:06:15 PM UTC-4, (unknown) wrote:
> Now I find that it is not exactly what I'm looking for
>
> Suppose my grid is [5,1,12] and I want to find to which of these values a data point of 4 is closest to.
>
> So I write
>
> grid = [5,1,12]
> print, VALUE_LOCATE(grid,4)
> 1
>
> But indeed it should be 0 since the 5 in the grid is closer to my data point...
> So in fact I need the nearest neighbor... :(

By the way, your grid has to be strictly ascending. If you pass a randomly ordered grid, expect random results.

VALUE_LOCATE() always finds the next lowest grid point, not the nearest gridpoint.

On the other hand, it's easy enough to check for this.

x = your data points
grid = [1, 5, 12]
ii = value_locate(grid, x) ;; You already know this much

;; See if the ii+1 grid point is closer
;; _no overflow_ ___ ii+1 sep ___ __ ii sep __
wh = where(ii LT 2 AND (grid[ii+1] - x) LT (x-grid[ii]), ct)

;; If we found some, then use those instead
if ct GT 0 then ii[wh] = ii[wh]+1

Craig
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: developing idl applications for use with Siemens e.soft with broker activities
Next Topic: SPLIT numbers into sub-numbers

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

Current Time: Wed Oct 08 19:57:28 PDT 2025

Total time taken to generate the page: 0.00465 seconds