05-08-2012 12:02 PM
Hi,
In my VI front panel I have a numeric control, a button, and a numeric display.
When user enter a number in the numeric control and press the button, the numeric display should show the average value of all the past 5 values entered in the numeric control, for example:
1st enter: 10 => average = 10 (because sum = 10)
2nd enter: 0 => average = 5 (because sum = 10 + 0 = 10)
3rd enter: 5 => average = 5 (you get the idea..)
4th enter: 1 => average = 4
5th enter: 14 => average = 6
6th enter: 2 => average = 4.4 (sum = 0 + 5 + 1 + 14 + 2 = 22, because the 1st value is thrown out)
How to write this VI?
Thank you!!
Solved! Go to Solution.
05-08-2012 12:51 PM
There are about a hundred ways to skin that cat! basically you need an array that can contain 0-5 elements (Some Kind of rolling buffer). One of the easiest ways relys on how Charts work with a strip update.
NOTE: history.length = 5, Update mode = Strip (O'scope would work identically for this but sweep would behave much different)
(Oh silly snippet tool! Man- I wish I had CCT!)
A queue could also be used as a rolling buffer by setting max number of elements. That would avoid the need to run in the UI thread
05-08-2012 08:52 PM
You can also use the arrays to hold the data in a shift register and find the average value of the last five elements.
Good luck
05-08-2012 11:58 PM
Hi,
Why do you need the "while loop", and the "wait" function?
Is it possible to do without these?
05-09-2012 12:14 AM
You can do without that but for using the above example you need to have the shift register in place. If you don't want to run continously keep the while loop and connect the stop terminal to True and remove the initalization part before the loop.
05-10-2012 03:50 AM
Hi P Anand,
With regard to your solution, I have a few question:
- what is the size of the array constant? Does it have to be initialized?
- if I keep entering numbers, will there be a limit to the size of the array?
05-10-2012 03:56 AM
@splee wrote:
- what is the size of the array constant? Does it have to be initialized?
No if you want to use this as a sub vi you leave the shift register uninitialized.
@splee wrote:
- if I keep entering numbers, will there be a limit to the size of the array?
If you want to limit the array size you need to use Replace array subset or Delete From array functions.
07-04-2012 11:40 AM - edited 07-04-2012 11:42 AM
Just curious...
- how to reset the 1st subarray of the "Split 1D array" to all zeros? Just in case I want to clear the buffer elements to all zero
- how to reset the output of the "Build array"?
@P Anand wrote:
You can also use the arrays to hold the data in a shift register and find the average value of the last five elements.
Good luck
07-06-2012 04:21 AM
Anyone has any idea how to reset/clear the array values?
07-06-2012 04:37 AM
Why not use the ready-to-use Pt-By-Pt-Mean? Life can be so easy...