03-21-2022 07:28 AM
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
03-21-2022 07:52 AM
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.
03-21-2022 08:10 AM
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
03-21-2022 08:13 AM
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.
03-21-2022 08:14 AM