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 #19663 is a reply to message #19659] Thu, 06 April 2000 00:00 Go to previous message
Med Bennett is currently offline  Med Bennett
Messages: 109
Registered: April 1997
Senior Member
Hi Ricardo,

You can use the SHIFT command in this situation - do something like

max_pos = where(data gt shift(data,-1) and data gt shift(data,1))

of course you have to check if the edge effects make sense in your case.

Ricardo Fonseca 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
[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: Sun Nov 30 08:25:18 PST 2025

Total time taken to generate the page: 0.01033 seconds