LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering and calculating averages of array subsets

Solved!
Go to solution

I've got a 2-D array coming out of a loop and I need to calculate average for subsets corresponding to iterations 0-9, 10-19, etc..  Additionally, I need to filter out values above and below acceptable limits before calculating average.  Any suggestions for how to approach this?

0 Kudos
Message 1 of 5
(2,525 Views)

My suggestion is to slog through each array subset, use a for loop to add up the values you want, keep track of the number of values, then divide out for the average. 

 

Every tenth reading you could clear the sum and counts.

 

The results would be saved in an array that only adds a value every tenth loop.

 

You could keep track of the one to ten value separately from the number of values accepted ( a.k.a. Filtering).

 

***

 

So my slog suggestion would be a for loop, two counters ( # accepted values and one to ten count), an array to store the averages and a numeric to hold the sum.


The filter criteria would produce a Boolean that would toggle adding to the sum and adding to the # accepted values.

 

The Sum and the counters need to be shift registers, and as I mentioned, there would be some logic to clear these shift registers every time the 'one to ten' count got to ten

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 5
(2,523 Views)

Thank you for the tip.  I'll see what I can do.

0 Kudos
Message 3 of 5
(2,494 Views)
Solution
Accepted by topic author MetroBob

Here is some example code doing just that. From this post, it looks like you need an upper bound as well. I'll leave that as an exercise for you.

Ben D.
Applications Engineer
National Instruments
Message 4 of 5
(2,464 Views)

Thanks, Ben.  I've added the upper bound as well and it works perfectly.

0 Kudos
Message 5 of 5
(2,447 Views)