Example Code

Adding Values to an Array by Iterating Through Each Value

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 will show the user how to create an array and iterate though each cell and add a new value to it.

 

Description

Arrays can be tricky. The Array Palette has a lot of useful functions and it is wise to go through and understand each function. You can easily expand this to work with bigger arrays and custom data.


Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Drop down an Initialize Array VI on the Block Diagram. Initialize all the values to 0 and create a 1 by 10 array.

  2. Next, create a For Loop and make the iteration terminal to 10 since we just want to fill up the first 10 columns of our array.

  3. Drop down a Replace Array Subset VI within the while loop. Wire a 0 constant to the first index position and the iteration terminal to the second index position. This will allow us to edit the first row and iterate through each column.

  4. We then add a Random Number (0-1) function to the 'new element' input of the Replace Array Subset VI just to add values to each column as we iterate through them.

 

Additional Information or References

VI Snippet

146.png

 

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

Applications Engineer
National Instruments

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