LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Adding values to array without overwriting

Solved!
Go to solution
Highlighted

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
(79 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
(75 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
(70 Views)
Solution
Accepted by topic author eddy1990
04-15-2019 08:00 AM

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
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 4 of 7
(69 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
(59 Views)

Thanks...worked exactly as I wanted..

0 Kudos
Message 6 of 7
(48 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!).

 


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 7 of 7
(40 Views)