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 #49605] Mon, 07 August 2006 09:24 Go to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
kuyper@wizard.net wrote:
> 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))

Agh! That should, of course, have been

index = where(diff eq min(diff))
[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 10:26:57 PDT 2025

Total time taken to generate the page: 0.64132 seconds