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

Home » Public Forums » archive » Re: Counting the lengths of continuous numbers in an array
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: Counting the lengths of continuous numbers in an array [message #61824] Fri, 08 August 2008 14:41 Go to previous message
andy.mcneel is currently offline  andy.mcneel
Messages: 3
Registered: August 2008
Junior Member
On Aug 8, 4:28 pm, mankoff <mank...@gmail.com> wrote:
> On Aug 8, 5:05 pm, andy.mcn...@gmail.com wrote:
>
>> Howdy folks.
>
>> Say I have the following array:  [1, 2, 3, 4, 7, 8, 11, 13, 14, 17,
>> 18, 19]
>
>> How would I tell IDL to go through this array and return the array [4,
>> 2, 1, 2, 3].....the lengths of the continuous groups of numbers in the
>> array?
>
>> Thanks!
>> -Andy McNeel
>
> I'm not sure how robust this is for other arrays, but I can get your
> 2nd array from your first like so, assuming the 1st array is "a". I
> didn't test boundary cases (runlength of 1 on beginning or end) or
> much else...
>
> IDL> aa = [a[0],a,0]
> IDL> b = where( (aa-shift(aa,1)) ne 1)
> IDL> c = b-shift(b,1)
> IDL> print, c[1:*]
>          4           2           1           2           3
>
>   -k.

This worked beautifully. Thanks! -Andy
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: heartbeat timeout
Next Topic: Re: Can i avoid the loop,help me speed up,thanks

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

Current Time: Wed Oct 08 11:32:04 PDT 2025

Total time taken to generate the page: 0.00717 seconds