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

Home » Public Forums » archive » Re: Avoiding a for cicle
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: Avoiding a for cicle [message #19660 is a reply to message #19659] Fri, 07 April 2000 00:00 Go to previous messageGo to previous message
landsman is currently offline  landsman
Messages: 93
Registered: August 1991
Member
In article <B51278FB.4C3D%zamb@physics.ucla.edu>,
Ricardo Fonseca <zamb@physics.ucla.edu> wrote:
> Hi
>
> I'm looking for a more efficient way of implementing the following
(i.e.
> avoiding the for cycle) which is a routine for finding local maximuns
>
> ; Data is a 1D Array
>
> s = Size(Data)
>
> nx = s[1]
>
> max_pos = [-1]
>
> for i = 1, nx-1 do $
> if ((Data[i] gt Data[i-1]) and (Data[i] gt Data[i+1])) then $
> max_pos = [[max_pos],i]
>
> ; and then throw away the first element...
>
> Any ideas? Thanks in advance, Ricardo
>

And JD Smith gave the solution:

> max_pos = where(data gt median(data,3))

Cool! I think this can be described as an almost literal example of
"thinking outside of the box"

Wayne Landsman landsman@mpb.gsfc.nasa.gov


Sent via Deja.com http://www.deja.com/
Before you buy.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Work at RSI!
Next Topic: Re: control precision for the axis ticks

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

Current Time: Sat Oct 11 13:38:08 PDT 2025

Total time taken to generate the page: 0.56518 seconds