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

Home » Public Forums » archive » Re: nearest number
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: nearest number [message #49615 is a reply to message #49612] Sun, 06 August 2006 12:34 Go to previous messageGo to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
bressert@gmail.com wrote:
> I thought about the problem more and realized a simple solution:
>
> smallest = min(abs(array - floating_value))
> index = where((array - floating_value) eq smallest, count)

Almost: that should be "abs(array-floating_value) eq smallest".

I'd be inclined to pull out the common code, and write it as

diff = abs(array-floating_value)
index = where(array eq min(array))
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Writing a structure containing empty strings
Next Topic: Re: file_lines and expand path

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

Current Time: Fri Oct 10 14:13:44 PDT 2025

Total time taken to generate the page: 0.32016 seconds