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 
Return to the default flat view Create a new topic Submit Reply
Re: generating sequences [message #85844 is a reply to message #85843] Fri, 13 September 2013 12:56 Go to previous messageGo to previous 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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: strsplit vectorized
Next Topic: Re: Filled area curve

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

Current Time: Wed Oct 08 17:00:12 PDT 2025

Total time taken to generate the page: 0.00369 seconds