# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Filtering and calculating averages of array subsets

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?

Message 1 of 5
(1,958 Views)

## Re: Filtering and calculating averages of array subsets

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
-------
Message 2 of 5
(1,956 Views)

## Re: Filtering and calculating averages of array subsets

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

Message 3 of 5
(1,927 Views)
Solution
Accepted by topic author MetroBob

## Re: Filtering and calculating averages of array subsets

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
(1,897 Views)

## Re: Filtering and calculating averages of array subsets

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

Message 5 of 5
(1,880 Views)