07-12-2013 11:11 AM
I have a table of data and would like to get an output of the average every 10 points. For example, the average of points 1-10, then the average of points 11-20, then 21-30, etc.
The challenge is that I do not know ahead of time how many points the sensor will collect each run because it depends on some external factor. I have attached a picture with some made-up data to illustrate what my table looks like. In the example I attached, the averages would be (11+34+125+77+44+232+25+213+22+89)/10 and (90+45+77+26+1+22+57+67+360+33)/10.
My initial attempt used a case structure which found a running average and then reset whenever a multiple of 10 was reached. However, this method does not seem very efficient. Does anyone have any better ideas?
Solved! Go to Solution.
07-12-2013 11:18 AM - edited 07-12-2013 11:19 AM
I use a function in Signal Processing >> Pt By Pt >> Prob. and Stat >> Mean.vi
You enter the number of items you want to calculate and as you add them one by one, the VI outputs a running average for the last N elements.
07-12-2013 12:28 PM
Like aputman said you could use the idea of signal processing pt by pt OR
You could write a simple looping function and a shift register to accomplish your task. You browse through your elements (10 elements), use array subset, make an average and loop it through.
07-12-2013 02:13 PM
How about this? Use Delete array subset to extract chunks for averaging, and a shift register to retain the remaining array.
07-12-2013 11:55 PM - edited 07-12-2013 11:55 PM
@JarleEkanger wrote:
How about this? Use Delete array subset to extract chunks for averaging, and a shift register to retain the remaining array.
It is typically not advisable to use "delete from array" in a tight loop. The constant memory reallocations due to array resizing are probably inefficient.
Here's one simple way to do it..
(If the number of points is not divisible by 10, the excess tail is discarded. You can easily modify that behavior if desired.)