LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging over loops

Solved!
Go to solution

Hello NI community.

 

I built a VI that basically outputs voltage from some maximum voltage to some minimum voltage back to that maximum in n steps (all user specified) and measures an input voltage at each step. This is all contained within a for loop to have multiple scans.

 

I would like to average the input voltages over all of the scans for each step and display it on an XY graph as the VI runs*. My idea is to have an array built for each step and each time a scan passes through that step it adds to that array. Then I can run it through a mean.vi and display it. I was hoping for advice on how to impliment this. Thank you for any that you guys can give and let me know if there is anything I need to clarify.

 

*Each scan passes through the output voltages twice but the input voltages will be different for scanning down vs up due to the physics of the experiment so I do not want to average the parts of the scans.

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

Without seeing any code I'd suggest the Mean point by point, or just Mean which takes an array of values that you can keep track of in a shift register.

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

I will post the .VI when I get back to the lab later. My issue is that wouldn't I need a separate shift register for each step, because I'd need a separate array for each step?

0 Kudos
Message 3 of 7
(4,037 Views)

Not necessarily.  One option might be to use an action engine, where you can give the new current value to a VI, which holds the running averages for each iteration.  Then when you want to get the current average it would be returned from that VI for the specified iteration.  Again when I see some code I'd be glad to whip something up.

Message 4 of 7
(4,026 Views)
Solution
Accepted by alexmer

I assume that the steps are equally spaced and the same for each scan. In that case, a plain graph is sufficient, no need for an xy graph.

Because of hysteresis, you need to create two arrays, one for the up and one for the down. Initialize it with zero and add the new values for each step as it arrives (fill from the back for the downs scan). Divide by the number of scans at the end to get the average for each.

Of course you can also create a single array for each up/down pair and use an xy graph.

 

 

Message 5 of 7
(4,016 Views)

@altenbach wrote:

 

Of course you can also create a single array for each up/down pair and use an xy graph. 


Here's what I had in mind. Modify as needed (To update each point with the average in real time would require significantly more code).

Message 6 of 7
(3,999 Views)

This worked perfectly. Thanks a ton.

0 Kudos
Message 7 of 7
(3,975 Views)