How to find the average function and get the previous readings in real time data collection

Dears,
May anyone let me know how I can find the average function and get the previous readings. As I would like to get the average value from real time readings, but I could not find the average function and how the get the previous readings in the function.
Looking forward your support.
Thank you indeed,
Chapter.

One way to accomplish this is to have a „Running Sum“ and an „Index.“
Let’s say you want to measure find the average force.
Set „Index“ = 1. Set „Running Sum“ = 0.
Start the sampling & measure the „force.“ Add the „force“ to the „Running Sum“ variable.
Calculate the average = „Running Sum“ / „Index“
Add one to the „Index“ & repeat the sampling.

Here is one I did when I was trying to measure average accel, force, time, and velocity (e.g., RS_A = running sum accel, RA_A = running average accel). PS: I had to add 1 to my index because the way my index was used elsewhere.
average.jpg
Hope this makes sense,
SFW