LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I repeat elements of an array?

I realize that this might be a simple problem but my thoughts keep getting jumbled up once I start playing with the loop blocks.

Anyways, I have a 1-D array that contains [1 2 3].  How do I change it into a 1-D array that contains [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3] (five of each element)?
0 Kudos
Message 1 of 4
(3,269 Views)
Hi Raine,

there are several ways to reach the goal 🙂 2 of them are shown in the vi!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(3,264 Views)
Thanks so much!

Both for the answer and for teaching me about answer ratings (I'm pretty new to the board Smiley Happy)
0 Kudos
Message 3 of 4
(3,257 Views)
GerdW's second answer is probably preferred, because it is flexible and you can turn the repeat count into a control and vary it later if needed. The interleave solution is a bit limited because the repeat count is hardcoded. It also gets unhandy if the desired repeat is more than a handful or so. 😉
 
Since you are just starting out, here are two more alternative solutions, just as an exercise. They are probably slightly less efficient than then second answer by GerdW, but try to understand them because they teach you some fundamentals about arrays, loops, and indexing, etc. 🙂
 
The image shows GerdW's two solutions on top and two more alternatives as mentioned.
 

Message Edited by altenbach on 02-07-2007 09:45 AM

Message 4 of 4
(3,245 Views)