Example Code

Average Last Five Values in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example takes the average of the last five values that have been read in every 1 second.

 

Description

This VI takes the average of the last five values that have been read in. The example reads the value of the control every second and adds that to the previous four values read which are stored in the shift register.  It then takes the average of them. It should be noted that using this method the average will only be accurate after 5 seconds because the shift registers are initialized to zero.

 One way to avoid the error of the first five samples giving an inaccurate average was suggested in this thread using the In Range Coerce VI.

 

Requirements

LabVIEW Base Development System 2012 or compatible

 

Steps to Implement or Execute Code

  1. Run the VI
  2. Change the Data value
  3. Notice the Average value changes every 1 second 

 

Additional Information or References

VI Block Diagram

4013.PNG

**This document has been updated to meet the current required format for the NI Code Exchange. **

  

 

 

Bryan H.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
jordankuehn
Member
Member
on

Average+Five+Values.png

The Colex Group
Lead Software Engineer
Certified LabVIEW Developer