HomeModules Module 1.5 (LabView Arrays) Connect
I ntroduce
C onnect
A pply
R eflect
E xtend

Connect - LabView
Arrays

Arrays

Definition

An array is a collection of data elements. Data elements are like storage slots for data. The data elements in an array can be numeric, boolean, string or cluster, but all data elements must be of the same type within an array. Arrays can be one or two-dimensional.

One Dimensional Arrays

One Dimensional arrays have elements and indices. Below is a 10-element, one-dimensional array. Notice that the first element has index 0, the second element has index 1, etc.


Creating a One Dimensional Array

Simple arrays are created by combining an array shell with a numeric, boolean, string or cluster data object (for our discussions, all data types will be numeric). To place an empty array shell, pop up in the Front Panel > Controls > Array & Cluster > Array

 

 

You will see the empty array shell in the Front Panel and it's terminal in the Block Diagram:

Notice that the array terminal looks empty to indicate it is still just an empty shell.

Next, drag a data object (in this case a numeric control) into the array shell. The array shell will automatically adjust to the data object's data type. You will see the array terminal change to indicate the data type of the array.


Manually Adding and Reviewing Array Content

By default you can only see the first array element. In order to see more elements of the array, select and stretch the array to the right. Make sure you get the frame corners or the one element will just stretch:

The above is showing the first five elements of this array. All the elements are empty. To manually enter data into the elements, select the elements one at a time and enter the data. In the example below, the data entered is the same value as the indices from index 0 - 4. To manually scroll through the array, click on the index display and increase/decrease its value. Notice that the current element is always on the left side of the array row:


Two Dimensional Arrays

Two-dimensional arrays require two indices: a row index and a column index. These are used like addresses to "look up" data elements in the array. Both indices are zero-based as in one-dimensional arrays. Below is a five-row, seven-column array which can hold 35 data elements.


Creating a Two Dimensional Array

You create a two-dimensional array by modifying a one-dimensional array. Pop up on the index display > Add Dimension. Then re-size the array display vertically to display the columns and manually add data as described above.


Creating One-Dimensional Arrays With a Loop

Manually creating and adding data to arrays can be tedious work. So loops are often used to create one-dimensional and two-dimensional arrays. Both For Loops and While Loops can create arrays and their boundaries automatically with auto indexing. For Loops are most commonly used to create arrays.

Below is an animated example of a For Loop auto-indexing a six-element, one-dimensional array. The element display has been re-sized to show a seventh element. Notice that the seventh element does not get filled and that all elements get filled at the end of the last loop iteration:


Wire Tunnels

Also notice that when a wire is brought outside a loop a Tunnel is created. In this case we want the Array Indicator outside the loop because we want the data at the end of all loop iterations.


Creating Two-Dimensional Arrays with Nested Loops

You can create nested For Loops to create a 2D array. The outer loop creates the row elements and the inner loop creates the column elements. The animated example below creates a six-column, eight-row 2D array filled with random numbers. The element display has been re-sized to show seventh column and fifth row elements. Notice that they are not filled with data and that all elements get filled at the end of the last loop iteration:


Clearing Array Data

To clear an array of data, pop-up on any Index Display > Empty Array:


Array Functions

Arrays can also be created and controlled by Array Functions. They are all found by popping-up in the Block Diagram > Functions > Array:

 

Array Size

The Array Size Function returns the number of elements in an array it is wired to.

Initialize Array

Initialize Array crates an array of dimension size elements containing the element value.

Build Array

Build Array links multiple arrays. It appends elements to an array.

And it concatenates multiple arrays

Array Subset

Array Subset returns a portion of an array starting at index and containing length elements.


Polymorphism

Definition

Labview arithmetic functions like Add, Multiply, Divide. Etc. are polymorphic. This means that the data structures on their inputs can be either scalar or array. If any inputs are of the array data structure, the output will be an array data structure. If the inputs have array structures of different sizes, the output will be an array that is the same size as the smallest input array.

Click here to move on to the next section (Apply).