[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Avoiding a for cicle
In article <B51278FB.4C3Demail@example.com>,
Ricardo Fonseca <firstname.lastname@example.org> wrote:
> I'm looking for a more efficient way of implementing the following
> avoiding the for cycle) which is a routine for finding local maximuns
> ; Data is a 1D Array
> s = Size(Data)
> nx = s
> 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 email@example.com
Sent via Deja.com http://www.deja.com/
Before you buy.