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 
Switch to threaded view of this topic 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 next 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
Re: Counting the lengths of continuous numbers in an array [message #61828 is a reply to message #61824] Fri, 08 August 2008 14:28 Go to previous messageGo to next message
mankoff is currently offline  mankoff
Messages: 131
Registered: March 2004
Senior Member
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.
Re: Counting the lengths of continuous numbers in an array [message #61968 is a reply to message #61824] Mon, 11 August 2008 06:08 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
>> 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


While I can't seem to find it this second my tired and jet lagged
brain is telling me that there is an built-in idl function to
calculate array[*]-array[1:*], which should be equivalent to above.
Now to remember the function.

Cheers,

Brian
  Switch to threaded view of this topic Create a new topic Submit Reply
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 09:15:02 PDT 2025

Total time taken to generate the page: 0.00629 seconds