Short Term Course on LabVIEW
PEC Deemed University Lecture- 4(5th NOV, 2006)
BY
RITA MAHAJAN LECTURER, E&Ec, PEC Deemed University
Arrays and Clusters DAY 4(lecture 4)
You Will Learn: A. About arrays
B. About generating arrays with loops C. Some basic array functions D. What polymorphism is E. About clusters F. Some cluster functions
Arrays
Collection of data elements that are of same type One or more dimensions, up to 2 -1 elements per dimension A dimension is the length, height, or depth of an array Elements accessed by their index First element is index 0
31
index 10-element array 2D array
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
0 0 1 2 3 4
Five-row by seven column array of 35 elements
Arrays contd
Arrays can be build of numeric, Boolean, string, and cluster data types. Consider using arrays when you work with a collection of similar data. 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.
Creating Array Controls and Indicators
To create an array control or indicator, 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. To add dimensions to an array one at a time, right-click the index display and select Add Dimension from the shortcut menu
1. Index Display, 2. Element Display
Array Controls and Indicators
1. Select the Array Shell from the Controls palette 2. Place data object inside shell
Add Dimension for 2D arrays
Creating Array Constants
1. Select Array Constant shell from the Array subpalette
2. Place the data object in the array shell
Creating and Using Arrays
Auto-Indexing loops accumulate arrays at their boundaries
For Loops auto index by default; While Loops do not
Creating 2D Arrays
Inner loop creates column elements Outer loop stacks them into rows
Common Array Functions
Array Size
Initialize Array
Array Subset
The Build Array Function
Appending an element
Building a higher dimension array
Concatenate Inputs (default)
The Index Array Function
Extracting an Element
Extracting a Row
Function inputs can be of different types All LabVIEW arithmetic functions are polymorphic
Combination Scalar + Scalar Array + Scalar Array + Array Array + Array
5 2 1 4 2 2 3 2 5 1 4 2 1 4 2 3 2 5 7 4 6 7 7
Polymorphism
Result Scalar Array Array Array
3 6 4
4 6 7
Run Polymorphism Example.vi
Exercise : build Array ,scale it, get sub array
Clusters
Data structure that groups data together Data may be of different types Analogous to record in Pascal or struct in C Elements must be either all controls or all indicators Thought of as wires bundled into a cable
15
Cluster Controls and Indicators
1. Select a Cluster shell from the Array & Cluster subpalette 2. Place objects inside the shell
16
Cluster Constants
Select a Cluster Constant shell from the Cluster subpalette Right-click on existing cluster and select Create>>Constant
Cluster Order
Elements have a logical order (start with 0) To change order, right-click on border and select Reorder Controls in Cluster...
18
Use Clusters to Pass Data to SubVIs
Use clusters to pass several values to one terminal Overcomes 28terminal limit Simplifies wiring
19
Cluster Functions
In the Cluster subpalette of the Functions palette Can also be accessed by right-clicking on the cluster terminal
(Terminal labels reflect data type) Bundle
Bundle By Name
20
Cluster Functions
Unbundle
Unbundle By Name
Unbundled cluster in the diagram
21
Polymorphism with Clusters
Polymorphic functions work with clusters Arithmetic functions can perform computations on clusters of numeric data
22
Summary
An array is a collection of elements of same data type numeric, Boolean, string, etc. Creating array or cluster controls/indicators is a two-step process 1. Get array or cluster shell 2. Place desired control/indicator inside the shell Loops can accumulate arrays at boundaries auto-indexing Array functions are in Array subpalette of Functions palette LabVIEW arithmetic functions are polymorphic input different data types Clusters group data that can be different types The Bundle and Unbundle functions are used to create and disassemble clusters