From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add 1D array elements with every iteration?

Solved!
Go to solution

Hello,

 

I have a 3 iteration For Loop which gives an array of 5 elements after its executed. With every iteration of the For Loop, how do I add each element to its previous value to form a final array of the elements' cummulative sum? For example:  

 

Array values for 1st iteration:   [A, B, C, D, E]

Array values for 2nd iteration:  [F, G, H,  I,  J]

Array values for 3rd iteration:   [K, L, M, N, O]

 

How can I make the Final Array to be a cummulative sum of i.e:  [(A+F+K), (B+G+L), (C+H+M), (D+I+N), (E+J+O)]?

 

Your help will be apreciated, Thank you!

0 Kudos
Message 1 of 3
(4,635 Views)
Solution
Accepted by PSerial

The Add function is polymorphic. Thus, if you feed it 2 1D arrays you'll get an array that is the sum of each element. With a loop you need to use a shift register or feedback node to keep track of the current sum.

 

For example:

Message 2 of 3
(4,618 Views)

Thanks, that works great! 🙂

0 Kudos
Message 3 of 3
(4,603 Views)