LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sum readings over an inner loop, reset to zero at each iteration of an outer loop

I feel this should be simple, but I must be missing something.  Searches are failing to give me anything useful

 

I've got a for loop inside a while loop.  I want to sum values (readings from a multimeter) as the for loop iterates, then start summing again at the next iteration of the while loop.

 

A bit more background:

* Afterwards I divide by the for loop count (specified on the front panel) to get an average, then write that to a file - that's easy.

* Within the for loop I toggle one of the applied voltages, so I'm actually building up two sets of data, which is why I can't use the averaging built in to the instrument as I previously did.

* I'm coming back to LabView after several years, so recalling some of the tricks isn't happening

0 Kudos
Message 1 of 5
(766 Views)

It would be easier to advise you on what to do if you could attach your code (actual code is preferred, but a screenshot is better than nothing). I think that your code can be significantly simplified.

 

One option that I would consider is to collect your data points in the for loop into an array and get the average outside of the loop.

0 Kudos
Message 2 of 5
(758 Views)

I'll have a fiddle with arrays in a minute, thanks.  The number of elements will be small enough not to have memory issues but I hadn't considered it because I don't need the elements

 

As for the code, I'm in the process of adding the inner loop into some existing code so there's nothing even sensibly screenshottable for now.  I may have to build something from scratch for testing/sharing if your suggestion isn't enough of a pointer

0 Kudos
Message 3 of 5
(750 Views)

Use a shift register on the FOR loop to keep your running sum.  You can then divide after the loop to get the average.  You just initialize the shift register to 0 before the FOR loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 5
(746 Views)