I have hundreds of thousands of data points stored in @data and need to do 100 data point moving average. Can anybody share the logic? I know I have to do pop or shift but just can't figure out how to do the moving average.
I think you are going to need to explain what you are trying to do in detail. Or maybe some knows what "100 data point moving average" means. Sample in and sample out data will be helpful.
There are a few different ways to define a moving average. Not in terms of perl (since that's your question) what algorithm would you use to calculate the moving average?
For example, a simple moving average for 100 data points would be something like:
This looks a little academic, so just in case I'll explain versus writing code here:
- Loop over your data pushing the data points into an array
- Track a 'running_total' of the values along the way
- If size of array < 99, goto start
- calc & print average
- shift array and subtract that amount from your running_total
- end of loop;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.