Example Code

Parse Array SubVI 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

Download All

Description

Overview

This VI will parse out every nth element of the input array into a new array.

 

Description

This example uses a For Loop to parse out every nth element of an array, e.g. if you want every 3rd element, you would put "3" in for Divisor (n).

 

Auto-indexing is used to tell the For Loop how many iterations to execute. The same functionality could be accomplished with an "Array Size" wired to the N input on the For Loop, but the Auto-indexing method looks cleaner.

 

Within the for loop, the divisor (n) value is multiplied by the iteration count to get the element index, and this is passed into an Index Array function. Auto indexing is used again, this time to output the Parsed array. The original array is also included as an output for reference.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

1. Download and open the VI.

2. Select a Divisor (value for n) on the Front Panel.
3. Edit the values of Input Array if desired.
4. Press run and observe that every nth value is outputted in the Parsed Array indicator.

 

Additional Information or References

 

Front Panel of the VI

Capture.PNG

 

Block Diagram of the VI

snippet.png

 

This SubVI differs from the Decimate 1D Array Function (on the Array Functions palette in LabVIEW) by making it easier to select n, eliminating the need to resize the function. For example, if you wanted to return every 3rd element, you could use Decimate 1D Array as below:

decimate.png

But if you wanted every 200th value, you would have to resize Decimate 1D array to this size, which might be impractical. This is where the attached example is really useful.

massive.PNG

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

Sincerely,

Chris G in AE

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