Professional Documents
Culture Documents
A. Arrays D. Auto-Indexing
B. Common Array Functions E. Clusters
C. Polymorphism F. Type Definitions
1
LESSON 5 Creating and Leveraging Data Structures
A. Arrays
Identify when to use arrays and learn how to create and initialize
arrays.
• 1D and 2D Arrays
• Creating an Array Control and Constant
• Initializing Arrays
2
A. Arrays
Arrays
A collection of data elements of
the same type.
3
A. Arrays
1D and 2D Examples
1D array - One row of 10 elements
0 3.2
1.2 1 2 38.04 5 5.1
6 76.0 81.0 9 2.5 1.7
4
A. Arrays
2D Arrays
2D arrays:
– Store elements in a grid.
– Require a column index and a row index to locate an element, both
of which are zero-based.
5
A. Arrays
Initializing Arrays
Uninitialized Array Initialized Array
6
LESSON 5 Creating and Leveraging Data Structures
Demonstration
Viewing Arrays
First element at
index 1 Second
The elements at index 0 are element at
not shown because element index 2
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.
7
Lesson 5 Creating and Leveraging Data Structures
8
LESSON 5 Creating and Leveraging Data Structures
Multimedia Module
Common Array Functions
9
B. Common Array Functions
Initialize Array
10
B. Common Array Functions
11
B. Common Array Functions
12
B. Common Array Functions
13
B. Common Array Functions
Search 1D Array
14
LESSON 5 Creating and Leveraging Data Structures
Activity 5-1
Using Array Functions
15
B. Common Array Functions
16
B. Common Array Functions
17
Lesson 5 Creating and Leveraging Data Structures
C. Polymorphism
Understand the ability of various VIs to accept input data of
different data types.
18
C. Polymorphism
Polymorphism
Polymorphism—The ability of VIs and functions to automatically
adapt to accept input data of different data types.
19
C. Polymorphism
20
Lesson 5 Creating and Leveraging Data Structures
D. Auto-Indexing
Use auto-indexed inputs and outputs to create graphs and arrays.
21
D. Auto-Indexing
Auto-Indexing
• Auto-Indexing Enabled • Auto-Indexing Disabled
22
D. Auto-Indexing
Waveform Graphs
23
D. Auto-Indexing
24
D. Auto-Indexing
25
D. Auto-Indexing
2D Array
1D Array
0 1 2 3 4 5 26
D. Auto-Indexing
Auto-Indexing Input
• Use an auto-indexing input
array to perform calculations
on each element in an array.
• Wire an array to an auto-
indexing tunnel on a For Loop.
• You do not need to wire the
count (N) terminal.
27
D. Auto-Indexing
28
LESSON 5 Creating and Leveraging Data Structures
Exercise 5-1
Manipulating Arrays
29
LESSON 5 Creating and Leveraging Data Structures
Exercise 5-1
Manipulating Arrays
In the All Data Channel case, how can you verify that the two approaches yield the same
results?
30
Lesson 5 Creating and Leveraging Data Structures
E. Clusters
Identify when to use clusters and be able to create them.
31
E. Clusters
Clusters
• Clusters group data elements of mixed types.
• Clusters are similar to a record or a struct in text-based
programming languages.
32
E. Clusters
• Fixed size
Arrays
• One data type
• Vary in size
33
LESSON 5 Creating and Leveraging Data Structures
Demonstration
Create a Cluster Control
34
E. Clusters
Cluster Order
Cluster elements have a
logical order unrelated to
their position in the shell.
35
E. Clusters
Autosizing Clusters
• Arrange elements in clusters
• NI recommends:
– Arrange vertically
– Arrange elements compactly
– Arrange elements in
preferred order
36
E. Clusters
Disassembling Clusters
• Unbundle By Name • Unbundle
– Use if all elements have – Use if some or all cluster
names. elements are unnamed.
37
E. Clusters
Modifying a Cluster
• Bundle By Name
– access elements in a cluster.
• Bundle
– some or all cluster elements are unnamed.
You must
wire the
input
cluster
terminal.
38
LESSON 5 Creating and Leveraging Data Structures
Demonstration
Creating a Cluster on the Block Diagram
39
E. Clusters
40
E. Clusters
Plotting Data
Use the Context Help window
to determine how to wire
multi-plot data to Waveform
Graphs, Charts, and XY
Graphs.
41
E. Clusters
Error Clusters
An error cluster contains the following elements:
– status
– code
– source
42
LESSON 5 Creating and Leveraging Data Structures
Exercise 5-2
Temperature Warnings VI─
Clusters
Create clusters, reorder clusters, and use the cluster functions to assemble and
disassemble elements.
43
LESSON 5 Creating and Leveraging Data Structures
Exercise 5-2
Temperature Warnings VI─
Clusters
What would happen if you reordered cluster elements?
What would happen if you added a cluster element to Weather Data Out?
44
Lesson 5 Creating and Leveraging Data Structures
F. Type Definitions
Identify and determine when to use a type definition, strict type
definition, or control.
45
F. Type Definitions
Control Options
You can save a custom control
as:
• Control
• Type Definition
46
LESSON 5 Creating and Leveraging Data Structures
Demonstration
Difference between Control, Type Def, and Strict Type Def
47
LESSON 5 Creating and Leveraging Data Structures
Demonstration
Creating and Identifying Type Definitions (Type Def)
48
LESSON 5 Creating and Leveraging Data Structures
Exercise 5-3
Temperature Warnings VI─
Type Definition
Create and modify a type-defined cluster control and use the type definition in a
calling VI and a subVI.
49
LESSON 5 Creating and Leveraging Data Structures
Exercise 5-3
Temperature Warnings VI─
Type Definition
Now that the Weather Data control is saved as a type definition, how many instances of
the cluster would need to be updated to add wind speed data?
50
LESSON 5 Creating and Leveraging Data Structures
Activity 5-2
Lesson Review
Refer to the participant guide to answer questions about what you have learned in this
lesson and then discuss the answers as a group.
51
Lesson Review
a. True
b. False
52
Lesson Review
a. True
b. False
You cannot drag an array data type into an array shell. However, you
can create two-dimensional arrays.
53
Lesson Review
54
Lesson Review
55
Lesson Review
56
Lesson Review
57
Lesson Review
4. You have input data representing a circle: X Position (I16), Y Position (I16),
and Radius (I16). In the future, you might need to modify your data to
include the color of the circle (U32).
What data structure should you use to represent the circle in your
application?
a. Three separate controls for the two positions and the radius
b. A cluster containing all of the data (X,Y)
c. A custom control containing a cluster
d. A type definition containing a cluster R
e. An array with three elements
58
Lesson Review
4. You have input data representing a circle: X Position (I16), Y Position (I16),
and Radius (I16). In the future, you might need to modify your data to
include the color of the circle (U32).
What data structure should you use to represent the circle in your
application?
a. Three separate controls for the two positions and the radius
b. A cluster containing all of the data (X,Y)
c. A custom control containing a cluster
d. A type definition containing a cluster R
e. An array with three elements
59