From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rolling averages

Solved!
Go to solution

I would like to have a file (excel) that has  11,12,13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25 or any random numbers in no specific order.

I would like to do an rolling calculation everytime the file reads. for example.

 

Add the first 5 numbers in the file and divide by 5 then drop the first number and move one to the right and get the next 5 number  then divide by 5 etc.

 

(11 + 12 + 13 + 14 + 15) / 5 = 13  the first time it reads then drop off the first number and move one to the right (12 + 13 + 14 + 15 + 16) / 5 = 14  then (13 + 14 + 15 + 16 + 17) / 5 = 15.

 

Can anyone help please?

0 Kudos
Message 1 of 4
(2,245 Views)
Solution
Accepted by topic author *E*

There are many examples of running / moving averages on this forum. But I do not recall them ever being called rolling averages. So you might want to search for running or moving average.

A recent thread started by me comes to mind.

 

The simplest example I have seen while loop with shift registers, especially if you do not need to change the sample size at run time.

 

 

Untitled.jpg

Message 2 of 4
(2,240 Views)

S1ack Thanks for your reply!

0 Kudos
Message 3 of 4
(2,232 Views)

What have you tried?  Can you show you code?

 

I would use a shift register to hold your 5 element array and use the Mean VI (in the Mathematics->Probability and Statistics palette) to calculate you mean.  You can then use the Replace Array Subset to put your new element in the array.  I used the Shift 1D Array with a -1 places so that the replaced element was always in the first element.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(2,231 Views)