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

Home » Public Forums » archive » Re: Getting rid of loops
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: Getting rid of loops [message #18926] Fri, 18 February 2000 00:00 Go to previous message
Michael Asten is currently offline  Michael Asten
Messages: 53
Registered: March 1999
Member
Try this.
Good luck,
Michael Asten


function fn,cycles
cycles_and=[cycles,max(cycles)]
cycles_shift=[cycles[0],cycles]
print , cycles_and
print , cycles_shift
b=where(cycles gt cycles_shift)
sub_cycles=[ cycles_shift[b[0]], cycles_and[b] ]
return,sub_cycles
end


cycles=[2,2,2,2,2,6,6,7,7,7,9,9,9,27,27,27]
print,fn(cycles)
;[2,6,7,9,27]>
end

Jacob Noel-Storr wrote:

> I am trying to create non-loopy IDL code for a project I am working on.
>
> I have a very long list of integers ('cycle numbers') and I need some way of
> creating an array that consists of just the cycle numbers. For example if I
> had:
>
>> cycles=[2,2,2,2,2,6,6,7,7,7,9,9,9,27,27,27]
>
> then I would want a function which would do this kid of thing:
>
>> print,fn(cycles)
> [2,6,7,9,27]
>
> At the moment this is done by looping through the data twice. Once to count
> how many different values there are and once to write the different values
> into an array.
>
> Any suggestions about how this could be achieved without the two 'for'
> loops?
>
> Thanks,
> Jacob
>
> --
> Jacob Noel-Storr
> Astronomy Department
> Columbia University / Biosphere 2 Center
> www.astro.bio2.edu/jacob/
> jake@astro.columbia.edu
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: How to do a weighted fit using pv-wave?
Next Topic: Re: TeXtoIDL fix for IDL 5.3

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

Current Time: Sat Oct 11 03:45:36 PDT 2025

Total time taken to generate the page: 1.44003 seconds