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

Home » Public Forums » archive » Looking for a search routine
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
Looking for a search routine [message #5274] Tue, 21 November 1995 00:00 Go to next message
jvkepner is currently offline  jvkepner
Messages: 10
Registered: November 1995
Junior Member
I have two 1D floating point vectors X and Y.
Y contains values sorted in increasing order. I am
looking for a function that for each element in the
X array, X(i), will return the index of the element in the
Y array that is nearest to X(i). Ideally it would
be a function that would look something like

y_ids = SEARCH(X,Y)

-Jeremy Kepner
Dept. of Astrophysics
Princeton University
Re: Looking for a search routine [message #5398 is a reply to message #5274] Mon, 27 November 1995 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
jvkepner@airy.Princeton.EDU (Jeremy Kepner) wrote:
> I have two 1D floating point vectors X and Y.
> Y contains values sorted in increasing order. I am
> looking for a function that for each element in the
> X array, X(i), will return the index of the element in the
> Y array that is nearest to X(i). Ideally it would
> be a function that would look something like
>
> y_ids = SEARCH(X,Y)

For each element of X, to find the index of the closest value in Y, do

D = MIN(ABS(Y-X(I)),LOC)

where I is the loop index for X, and LOC is the index of the closest value in
Y.
You might be able to do this without a loop, but I'm not sure exactly how.

Cheers,
Liam.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Please explain...
Next Topic: Importing IDL Postscript output into Windows apps

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

Current Time: Wed Oct 08 17:19:14 PDT 2025

Total time taken to generate the page: 0.00601 seconds