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 
Return to the default flat view Create a new topic Submit Reply
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 previous 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
[Message index]
 
Read Message
Read Message
Read Message
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: Fri Oct 10 17:20:53 PDT 2025

Total time taken to generate the page: 1.04128 seconds