I am facing a problem as stated below.
I have an array a=[0.5 0.2] and another array b=[1 2]. Since b=1, I have to repeat a 4 times (3*b+1) and since b=2, I have to repeat a 7 times (3*b+1). The final array would be
c = [0.5 0.5 0.5 0.5 0.2 0.2 0.2 0.2 0.2 0.2 0.2]. I would like to program this in Labview, without a formula loop. Any help would be highly appreciated.
Solved! Go to Solution.
I don't know what you mean by a "formula loop".
But you can change arrays. And you will want to use a For Loop. Look at Insert into Array since you will be inserting new values into the middle of the array.
so you want to initialize some arrays and concatenate them to one bigger array?
(More recent LabVIEW versions than that LV2011 I used here already provide "concatenating" loop tunnels!)
I tried for loops but the values in the output array are getting replaced by the new ones.
When you've attempted something that didn't work, you should attach that VI so we can show you how to fix it.
PS: I like Gerd's implementation better than what I was visualizing.
I would like to program this in Labview, without a formula loop.
As others have said, if there are special requirements you actually need to define what they mean. "Formula loop" is not a recognized part of LabVIEW (we have formula nodes, we have loops, even "FOR loops", but nothing of that matches your terms. Also the word you are looking for is appending. The word "adding" is used for something else and you are not doing that here.
Typically we use the structure most appropriate for the job, so if you have some silly extra requirements, it is either a puzzle or homework, and maybe you should try to solve it by yourself. If we are allowed to use all LabVIEW tools, there are plenty of solutions. Gerd already gave you one, here's another random solution.
These solutions are scalable, which is always important. They work equally well if the input arrays (both same size) have 5, 18, or thousands of elements. Only for the special case where both input arrays always have the same very small number of elements (e.g. 2), a loop-free solution is possible (not recommended!).