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 #19636 is a reply to message #19627] Tue, 11 April 2000 00:00 Go to previous messageGo to previous message
Benno Puetz is currently offline  Benno Puetz
Messages: 16
Registered: March 2000
Junior Member
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
"J.D. Smith" wrote:
<blockquote TYPE=CITE>Ricardo Fonseca wrote:
<br>>
<br>> Hi
<br>>
<br>> I'm looking for a more efficient way of implementing the following
(i.e.
<br>> avoiding the for cycle) which is a routine for finding local maximuns
<br>>
<br>> ; Data is a 1D Array
<br>>
<br>> s = Size(Data)
<br>>
<br>> nx = s[1]
<br>>
<br>> max_pos = [-1]
<br>>
<br>> for i = 1, nx-1 do $
<br>>&nbsp;&nbsp;&nbsp; if ((Data[i] gt Data[i-1]) and (Data[i] gt Data[i+1]))
then $
<br>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; max_pos = [[max_pos],i]
<br>>
<br>> ; and then throw away the first element...
<p>max_pos = where(data gt median(data,3))
<br>&nbsp;</blockquote>
While this is rather efficient concerning code length,
<br>&nbsp;
<pre>&nbsp;maxpos = WHERE(TEMPORARY(data[0:nx-3]) LT TEMPORARY(data[1:nx-2]) AND&nbsp; $</pre>

<pre> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TEMPORARY(data[1:nx-2]) GT TEMPORARY(data[2:nx-1])) + 1</pre>

<pre></pre>
should execute faster, especially for longer arrays
<br>--&nbsp;<br>
Benno Puetz<br>
Kernspintomographie<br>
Max-Planck-Institut f. Psychiatrie&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;
Tel.: +49-89-30622-413<br>
Kraepelinstr. 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fax : +49-89-30622-520<br>
80804 Muenchen, Germany
<br>&nbsp;</html>
[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 14:59:19 PDT 2025

Total time taken to generate the page: 0.48244 seconds