04-15-2019 09:21 AM
Hi
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]=1, I have to repeat a[1] 4 times (3*b[1]+1) and since b[2]=2, I have to repeat a[2] 7 times (3*b[2]+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.
04-15-2019 09:29 AM
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.
04-15-2019 09:34 AM
I tried for loops but the values in the output array are getting replaced by the new ones.
Thanks
04-15-2019 09:37 AM
04-15-2019 09:43 AM
@eddy1990 wrote:
I tried for loops but the values in the output array are getting replaced by the new ones.
Thanks
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.
04-15-2019 10:01 AM
Thanks...worked exactly as I wanted..
04-15-2019 10:13 AM - edited 04-15-2019 10:17 AM
@eddy1990 wrote:
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!).