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

Home » Public Forums » archive » repeating elements of 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
repeating elements of an array [message #89347] Sun, 24 August 2014 09:42 Go to next message
Cleo Drakos is currently offline  Cleo Drakos
Messages: 1
Registered: August 2014
Junior Member
Hi guys

First I want to arrange two values (-50 and 40) in the range of 10, so that I get the following array:

a = [-50 -40 -30 -20 -10 0 10 20 30 40]
Now, I want to repeat each element of array 5 times so that I can get the following result:

ans1 = [-50 -50 -50 -50 -50 -40 -40 ....40]

I also want to repeat the whole array 5 times to get the following result:

ans2 = [-50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 .......]

How can I do it? I hope someone can help me.

cleo
Re: repeating elements of an array [message #89348 is a reply to message #89347] Sun, 24 August 2014 13:09 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Sunday, August 24, 2014 12:42:53 PM UTC-4, Cleo Drakos wrote:
> Hi guys
>
>
>
> First I want to arrange two values (-50 and 40) in the range of 10, so that I get the following array:
>
>
>
> a = [-50 -40 -30 -20 -10 0 10 20 30 40]
>
> Now, I want to repeat each element of array 5 times so that I can get the following result:
>
>
>
> ans1 = [-50 -50 -50 -50 -50 -40 -40 ....40]
>
>
>
> I also want to repeat the whole array 5 times to get the following result:
>
>
>
> ans2 = [-50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 .......]
>
>
>
> How can I do it? I hope someone can help me.
>
>
>
> cleo

It sounds like I might be doing your homework, but ...

a = [-50:40:10]

ncopies = 5
nelements = n_elements(a)
npts = ncopies*nelements

ans1 = rebin(a, npts, /sample)

; build up answer by concatenation
ans2 = []
for i = 1, ncopies do ans2 =[ans2, a]

; or else build up answer by copying
ans2 = intarr(npts)
for i = 0, npts-1, nelements do ans2[i] = a

TTFN,

David
Re: repeating elements of an array [message #89349 is a reply to message #89347] Sun, 24 August 2014 13:13 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
First, the original array:

IDL> a = findgen(10)*10-50

Now, repeat each element of the array:

IDL> aRepeat= rebin(a, 50, /sample)

Replicating the array is a little more involved, but still pretty straightforward:

IDL> aReplicate = reform(a#replicate(1., 5), 50)

Fun with reform and rebin!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: CPU overload when saving a file
Next Topic: Add event handling to an ENVI display group

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

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

Total time taken to generate the page: 0.00456 seconds