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

Home » Public Forums » archive » generating sequences
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
generating sequences [message #85841] Fri, 13 September 2013 12:01 Go to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
Hi,

I thought this should be very easy, but I cannot find how to do it IDL. Say we have a vector with a few starting values:

a=[1, 12, 90]

and we want to generate sequences of 3 numbers starting with these values, so that we end up with:

[1, 2, 3, 12, 13, 14, 90, 91, 92]

How is this done in IDL?

Thanks,
Seb
Re: generating sequences [message #85842 is a reply to message #85841] Fri, 13 September 2013 12:10 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
On 2013-09-13 21:01, spluque@gmail.com wrote:
> Hi,
>
> I thought this should be very easy, but I cannot find how to do it IDL. Say we have a vector with a few starting values:
>
> a=[1, 12, 90]
>
> and we want to generate sequences of 3 numbers starting with these values, so that we end up with:
>
> [1, 2, 3, 12, 13, 14, 90, 91, 92]
>
> How is this done in IDL?

IDL> print,reform(transpose([[a],[a+1],[a+2]]),9)
1 2 3 12 13 14 90 91 92
Re: generating sequences [message #85843 is a reply to message #85842] Fri, 13 September 2013 12:29 Go to previous messageGo to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
On Friday, September 13, 2013 2:10:40 PM UTC-5, Mats Löfdahl wrote:
> On 2013-09-13 21:01, spluque@gmail.com wrote:
>
>> Hi,
>
>>
>
>> I thought this should be very easy, but I cannot find how to do it IDL. Say we have a vector with a few starting values:
>
>>
>
>> a=[1, 12, 90]
>
>>
>
>> and we want to generate sequences of 3 numbers starting with these values, so that we end up with:
>
>>
>
>> [1, 2, 3, 12, 13, 14, 90, 91, 92]
>
>>
>
>> How is this done in IDL?
>
>
>
> IDL> print,reform(transpose([[a],[a+1],[a+2]]),9)
>
> 1 2 3 12 13 14 90 91 92

What if the sequence for each starting value was 1000 instead of 3?...

I'm surprised one can't just do:

print, a + indgen(3)
Re: generating sequences [message #85844 is a reply to message #85843] Fri, 13 September 2013 12:56 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
On 2013-09-13 21:29, spluque@gmail.com wrote:
> On Friday, September 13, 2013 2:10:40 PM UTC-5, Mats Löfdahl wrote:
>> On 2013-09-13 21:01, spluque@gmail.com wrote:
>>> Hi,
>>
>>> I thought this should be very easy, but I cannot find how to do it IDL. Say we have a vector with a few starting values:
>>
>>> a=[1, 12, 90]
>>
>>> and we want to generate sequences of 3 numbers starting with these values, so that we end up with:
>>
>>> [1, 2, 3, 12, 13, 14, 90, 91, 92]
>>
>>> How is this done in IDL?
>>
>> IDL> print,reform(transpose([[a],[a+1],[a+2]]),9)
>>
>> 1 2 3 12 13 14 90 91 92
>
> What if the sequence for each starting value was 1000 instead of 3?...

Let's make a sequence of length N. N=1000 will be kind of a waste of
space so let's just do

IDL> N=7
IDL> print,reform(transpose(rebin(a,3,N,/samp) + [1,1,1] # indgen(N)),3*N)
1 2 3 4 5 6
7 12 13 14 15 16
17 18 90 91 92 93
94 95 96


If you want to generalize the solution further to a of any length, just
substitute n_elements(a) for the number 3 and replicate(1,n_elements(a))
for [1,1,1].

> I'm surprised one can't just do:
>
> print, a + indgen(3)

You can, but of course you'd get a different answer:

IDL> print, a + indgen(3)
1 13 92
Re: generating sequences [message #85845 is a reply to message #85844] Fri, 13 September 2013 13:36 Go to previous message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
On Friday, September 13, 2013 2:56:58 PM UTC-5, Mats Löfdahl wrote:
> On 2013-09-13 21:29, spluque@gmail.com wrote:
>
>> On Friday, September 13, 2013 2:10:40 PM UTC-5, Mats Löfdahl wrote:
>
>>> On 2013-09-13 21:01, spluque@gmail.com wrote:
>
>>>> Hi,
>
>>>
>
>>>> I thought this should be very easy, but I cannot find how to do it IDL. Say we have a vector with a few starting values:
>
>>>
>
>>>> a=[1, 12, 90]
>
>>>
>
>>>> and we want to generate sequences of 3 numbers starting with these values, so that we end up with:
>
>>>
>
>>>> [1, 2, 3, 12, 13, 14, 90, 91, 92]
>
>>>
>
>>>> How is this done in IDL?
>
>>>
>
>>> IDL> print,reform(transpose([[a],[a+1],[a+2]]),9)
>
>>>
>
>>> 1 2 3 12 13 14 90 91 92
>
>>
>
>> What if the sequence for each starting value was 1000 instead of 3?...
>
>
>
> Let's make a sequence of length N. N=1000 will be kind of a waste of
>
> space so let's just do
>
>
>
> IDL> N=7
>
> IDL> print,reform(transpose(rebin(a,3,N,/samp) + [1,1,1] # indgen(N)),3*N)
>
> 1 2 3 4 5 6
>
> 7 12 13 14 15 16
>
> 17 18 90 91 92 93
>
> 94 95 96
>
>
>
>
>
> If you want to generalize the solution further to a of any length, just
>
> substitute n_elements(a) for the number 3 and replicate(1,n_elements(a))
>
> for [1,1,1].

Very impressive, I'll have to study these functions for a while!

Thanks,
Seb
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: strsplit vectorized
Next Topic: Re: Filled area curve

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

Current Time: Wed Oct 08 15:05:40 PDT 2025

Total time taken to generate the page: 0.00643 seconds