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

Home » Public Forums » archive » Finding the closest value in an array...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Finding the closest value in an array... [message #38780] Tue, 30 March 2004 01:34 Go to previous message
timrobishaw is currently offline  timrobishaw
Messages: 16
Registered: June 2003
Junior Member
Hi there.

Seems like every few minutes I'm taking a scalar and trying to locate
which value in an array it's closest to. VALUE_LOCATE() finds the
interval of a monotonic vector that the value lives in, so it's not
quite what I'm looking for, but it's awfully close! I end up just
doing this:

IDL> useless = min(abs(vector-value),minindx)
IDL> closest = vector[minindx]

I'm embarrassed to admit I don't know of any other way to do this. Is
there some slick way like VALUE_LOCATE() to do this? I find it
aesthetically unpleasant to have to set something to a useless value
just to get at the corresponding index; however, I can't see any way
to be clever about it. And it's pretty much to the point: I'd bet
VALUE_LOCATE() is doing a lot more stuff behind the scenes than the
simple two lines above (judging from the old Goddard library routine).

I guess I'm surprised that I haven't found some canned routine for
this (like in the Goddard library) given that I usually need to find
closest values more often than intervals in which a value lives.
-Tim.
[Message index]
 
Read Message
Read Message
Previous Topic: Re: using TVRD(true=0) with a 24-bit image and decomposed=0
Next Topic: Is it possible a transparent image in space ???

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

Current Time: Fri Oct 10 12:35:26 PDT 2025

Total time taken to generate the page: 0.32114 seconds