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

Home » Public Forums » archive » Search routines
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: search routine [message #54387 is a reply to message #54243] Fri, 01 June 2007 07:20 Go to previous messageGo to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
cmancone@ufl.edu wrote:
> On Jun 1, 9:11 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
>> Laurens wrote:
>>> Hi folks,
>>> From Martin Schultz (posted in 1999) I found the following array-search
>>> algorithm which seems to do a fine job.
>>> Except that i'm not able to catch the first element in the array.
>>> Example:
>>> Array = [0,80,100,120,180,300]
>>> result = search, Array, 4.53
>>> It should return index 0, if I understand it correctly, but it returns 1
>>> instead. Now I don't quite follow the logic of the function, so maybe
>>> someone for which it's easy to see can help me in the right direction?
>> You could use the built-in function value_locate instead:
>>
>> result=value_locate(array,4.53)
>>
>> which returns 0.
>>
>> Ciao,
>> Paolo
>
>
> If you wanted to program it up, you'd be better off with array
> operations anyway, something like this:
>
> function search_array, arr, val
> w = where( arr - val le 0 AND shift(arr,-1) - val ge 0 )
> return,w

"where" is much slower, so I would not recommend it.

Ciao,
Paolo

>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Ergonomic Mobile Computing
Next Topic: Plots

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

Current Time: Wed Oct 08 21:14:13 PDT 2025

Total time taken to generate the page: 0.95988 seconds