Arrays group data elements of the same type. An
array consists of elements and dimensions. Elements are the data
that make up the array. A dimension is the length, height, or
depth of an array. An array can have one or more dimensions and
as many as
231-1
2
31
1
elements per dimension, memory permitting.
You can build arrays of numeric, Boolean, path, string,
waveform, and cluster data types. Consider using arrays when you
work with a collection of similar data and when you perform
repetitive computations. Arrays are ideal for storing data you
collect from waveforms or data generated in loops, where each
iteration of a loop produces one element of the array.
You cannot create an array of arrays. However, you can create an
array of
clusters, where each cluster contains one
or more arrays. Refer to
Clusters for
more information about clusters.
Array elements are ordered. An array uses an index so you can
readily access any particular element. The index is zero-based,
which means it is in the range
0
0
to
n-1
n
1
, where
n
n
is the number of elements in the array. For example, if you
create an array of the planets in the solar system,
n=9
n
9
for the nine planets, so the index ranges from
0
0
to
8 8. Earth is the third planet, so it
has an index of
2
2.
Creating Array Controls and Indicators
To create an
array control or indicator as shown
in
Figure 1, select an
array on the
Controls>>All Controls>>Array & Cluster
palette, place it on the front panel, and drag a control or
indicator into the
array shell. If you attempt to
drag an invalid control or indicator such as an XY graph into
the array shell, you are unable to drop the control or
indicator in the
array shell.
You must insert an object in the array shell
before you use the array on the block
diagram. Otherwise, the array terminal appears
black with an empty bracket.
Two-Dimensional Arrays
A 2D array stores elements in a grid. It requires a column
index and a row index, both of which are zero-based, to
locate an element.
Figure 2 shows a
6
6-column by
4
4-row 2D array, which contains
6×4=24
6
4
24
elements.
To add dimensions to an array one at a time, right-click the
index display and select
Add Dimension from the
shortcut menu. You also can use the
Positioning
tool to resize the index display until you have as many
dimensions as you want.
Figure 3 is an example of
an uninitialized 2D array control.
Creating Array Constants
You can create an array constant on the block
diagram by selecting an array constant from the
Functions>>All Functions>>Array palette, placing
it on the block diagram, and dragging a constant into the
array shell. Array constants are useful for
passing data into a subVI.
"A full introductory course on programming with LabVIEW."