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 #49608 is a reply to message #49605] Mon, 07 August 2006 08:09 Go to previous messageGo to previous message
mchinand is currently offline  mchinand
Messages: 66
Registered: September 1996
Member
In article <1154956439.920334.266030@m73g2000cwd.googlegroups.com>,
Timm Weitkamp <timm.weitkamp@iss.fzk.de> wrote:
> 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))
>
> Or simply,
> void = min(abs(array - floating_value), index)
>

I was going to post the same thing last night, but this optional argument to MIN will only return
the index of the first element that is the minimum of the array even if there are multiple
occurrences of the minimum value. Which may be alright, depending on what the original poster
wants.

--Mike

--
Michael Chinander
m-chinander@uchicago.edu
Department of Radiology
University of Chicago
[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: Sat Oct 11 02:09:43 PDT 2025

Total time taken to generate the page: 1.60175 seconds