Looking for a search routine [message #5274] |
Tue, 21 November 1995 00:00  |
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  |
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.
|
|
|