06-14-2012 05:39 PM
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?
Solved! Go to Solution.
06-14-2012 05:51 PM
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
06-15-2012 02:39 PM
Thank you for the tip. I'll see what I can do.
06-26-2012 08:59 AM
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.
06-26-2012 12:38 PM
Thanks, Ben. I've added the upper bound as well and it works perfectly.