4 Relating Data

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Relating Data

Arrays
Clusters
Type Definitions

1
A. Arrays
An array consists of elements and dimensions
Elements: data that make up the array
Dimension: the length, height, or depth of an array
An array can have one or more dimensions
and as many as (231)1 elements per
dimension, memory permitting
Consider using arrays when you work with
a collection of similar data and when you
perform repetitive computations

2
A. Arrays
The first element shown in the array (3.00) is at
index 1 and the second element (1.00) is at index
2
The element at index 0 is not shown in this image,
because element 1 is selected in the index display
The element selected in the index display always
refers to the element shown in the upper left
corner of the element display

3
A. Arrays Creating
1. Place an array shell on the front panel
2. Drag a data object or element into the array
shell

4
A. Arrays 2D Array
Stores elements in a grid
Requires a column index and a row index to locate
an element, both of which are zero-based
To create a multidimensional array on the front
panel, right-click the index display and select Add
Dimension from the shortcut menu
You also can resize the index display until you have
as many dimensions as you want

5
A. Arrays Initializing
You can initialize an array, or leave it uninitialized
For initialized arrays, you define the number of
elements in each dimension, and the contents of
each element
Uninitialized arrays have dimension but no
elements

6
A. Arrays Creating Constants
To create an array constant:
Select an array constant on the
Functions palette
Place the array shell on the block diagram
Place a constant in the array shell
You can use an array constant to store
constant data or as a basis for comparison
with another array
Array constants also are useful for passing data
into a subVI

7
A. Arrays Auto-indexing
If you wire an array to or from a For Loop or While
Loop, you can link each iteration of the loop to an
element in that array by enabling auto-indexing on
tunnel
The tunnel changes from a solid square to the
image shown above to indicate auto-indexing

8
A. Arrays Auto-indexing Input
For Loop executes
a number of times
equal to the number
of elements in the
array

9
A. Arrays Auto-indexing Input
If the iteration count terminal is wired and
arrays of different sizes are wired to auto-
indexed tunnels, the actual number of iterations
becomes the smallest of the choices.

10
A. Arrays Auto-indexing Output
When you auto-index an array output tunnel, the
output array receives a new element from every
iteration of the loop
Auto-indexed output arrays are always equal in
size to the number of iterations

11
A. Arrays Creating 2D Arrays
You can use two For Loops, one inside the other,
to create a 2D array

12
B. Clusters
Clusters group data elements of mixed types
Similar to a record or a struct in text-based
programming languages

13
B. Clusters Array vs Cluster
Clusters differ from arrays in that they are a fixed
size
Clusters can contain mixed data types; arrays
contain only one data type
Like an array, a cluster is either a control or an
indicator and cannot contain a mixture of controls
and indicators

14
B. Clusters Creating
To create a cluster control or indicator on the
front panel:
Place a cluster shell on the front panel
Drag a data object or element,
which can be a numeric, Boolean,
string, path, refnum, array, or
cluster control or indicator into
the cluster shell

15
B. Clusters Constants
To create a cluster constant:
1. Select a cluster constant on the Functions palette
2. Place the cluster shell on the block diagram
3. Place a constant in the cluster shell

If you have a cluster control or indicator, right-click


the cluster on the block diagram and select
CreateConstant from the shortcut menu

16
B. Clusters Order
Cluster elements have a logical order unrelated to
their position in the shell
You can view and modify the
cluster order by right-clicking
the cluster border and
selecting Reorder Controls
In Cluster from
the shortcut menu

17
B. Clusters Assembling a Cluster
Use the Bundle function to assemble a new
cluster

18
B. Clusters Modifying a Cluster
Use the Bundle By Name or the Bundle function
to modify an existing cluster

19
B. Clusters Disassembling a Cluster
Use the Unbundle By Name or Unbundle
function to use individual items in a cluster

20
B. Clusters Error Clusters
LabVIEW uses error clusters to pass error
information
An error cluster contains the following elements:
status: Boolean value that reports True if an error
occurs
code: 32-bit signed integer that identifies the error
source: String that identifies where the error occurred

21
C. Type Definitions Custom Controls
Use custom controls and indicators to extend
the available set of front panel objects
1. Create and save a
custom control
or indicator
2. Use the custom control
or indicator on other
front panels

22
C. Type Definitions Control Editor
Use the Control Editor window to customize
controls and indicators
To display the Control Editor
window, right-click a control
or indicator and select
AdvancedCustomize

23
C. Type Definitions
You can save a custom control as:
Control
Type Definition
Strict Type Definition

24
C. Type Definitions Control Type
Control
No connection between the custom control or
indicator you saved and the instance of the
custom control or indicator in the VI
Update the file, but the
instances are not updated

25
C. Type Definitions Type Definition
Type Definition (type def):
Edit the saved file, and have all instances update with
the changes made
Forces the data type of each instance to be identical
Example:
Add an item to the type definition of an
enum, the instances of the enum
update with the new item
If you resize the enum front panel
control type definition, the instances
of the enum do not resize

26
C. Type Definitions Strict Type
Definition
Strict Type Definition:
Similar to a type definition, except a strict type
definition forces everything about an instance to
be identical to the strict type definition, except:
label
description
default value

27

You might also like