LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding values to array without overwriting

Solved!
Go to solution

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.

0 Kudos
Message 1 of 7
(4,415 Views)

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.

0 Kudos
Message 2 of 7
(4,411 Views)

I tried for loops but the values in the output array are getting replaced by the new ones.

Thanks

0 Kudos
Message 3 of 7
(4,406 Views)
Solution
Accepted by topic author eddy1990

Hi eddy,

 

so you want to initialize some arrays and concatenate them to one bigger array?

Like this?

check.png

(More recent LabVIEW versions than that LV2011 I used here already provide "concatenating" loop tunnels!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(4,405 Views)

@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.

0 Kudos
Message 5 of 7
(4,395 Views)

Thanks...worked exactly as I wanted..

0 Kudos
Message 6 of 7
(4,384 Views)

@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.

 

BuildSpecialArray.png

 

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!).

 

0 Kudos
Message 7 of 7
(4,376 Views)