Sie sind auf Seite 1von 27

EMEM 280: Measurements, Instrumentation, & Controls

LabVIEW Fundamentals: Arrays & Clusters


John D. Wellin Winter Quarter, 2005-2

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays
Use arrays to collect and organize elements of the same data 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.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays
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.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays
Row Index Column Index

2-D array: N x M Read: N by M, implies N rows and M columns (some may not be shown). Indices start counting at 0.
Column (column index = 1)

Row
(row index = 3) 3-D or greater have more index controls, but the view remains 2-D (row and column controls move to bottom).

Element
(index = 5,3)

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays
8 x 3 array of numerics
Do not count these that are grayed outthey are uninitialized

Also, if you try to index past the bounds, the default data value is assumed

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

1-D arrays (sometimes called vectors) can be visualized and shown as a single row or a single column. However, when built into 2-D arrays, 1-D arrays become rows. Therefore, it is most expedient to think of a 1-D array as a single row, regardless of the way it is shown on the front panel.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

To create an array on the front panel, select the array shell from the palette, and then drag the desired element type into it. Add/delete dimensions by expanding the index control, or right-click and select Any property changes made to one element in the array apply to all elements.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

In a similar fashion, one way to create an array on the block diagram is to select the array constant shell from the palette, and then drag the desired element type into it.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

Also, as previously discussed, arrays can be automatically constructed by enabling indexing in loops. Indexing is also useful for deconstructing an array for element-by-element processing.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

Finally, the full complement of functions available on the Array palette can be used for all sorts of creation and processing tasks. One example: Initialize Array.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

Note padding

Another example is Build Array, which can be used in two ways: to append arrays of dimensions N and N-1, or to concatenate if all are of the same dimension. If all are of dimension N, then the appended array is of dimension N+1.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

Like many of the array functions, Build Array can be expanded to allow for any number of inputs; and the input glyphs change to mimic the wired input dimensions.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays
Index Array: select individual elements, rows, columns, etc. from higher-dimensional arrays. Note expansion and glyph concepts, as well as the adaptive terminals 3-D Version
page index

row index
column index

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays
Use the standard, polymorphic numeric functions with arrays as well, which work on an element-by-element basis. Note that these are not the typical matrix operations that mathematicians speak of. There is also the special function Add Array Elements, and Multiply Array Elements.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Arrays

The typical mathematical operations for matrices are found under the All Functions>>Analyze>>Mathematics>>Linear Algebra palette.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters
Clusters group data elements of mixed types. An example of a cluster is the LabVIEW error cluster, which combines a Boolean value, a numeric value, and a string. Another example is the Waveform data type, which is essentially a specialized cluster of a start time, a time increment, and a 1-D array of numerics.
Most clusters on the block diagram have a pink wire pattern and data type terminal. Clusters of numeric values, sometimes referred to as points, have a brown wire pattern and data type terminal. You can wire brown numeric clusters to numeric functions to perform the same operation simultaneously on all elements of the cluster.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters

(all controls here)

This one cluster contains numeric, boolean, and string data types altogether. The associated terminal is pink because of the mixed types. Note that all of the objects are assigned the same functionality as control or indicator, and cannot be mixed in this manner.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters

To create a cluster on the front panel, select the cluster shell from the palette, and then drag the desired elements into it. The elements are arranged in the cluster in the same order in which they are addedbut this arrangement can be changed.

SEE NEXT!
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters
Reordering elements of a cluster

Right-click

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters
The ordering of the elements is important, because it is according to the order that the elements are read from or written to.

The Bundle function: use to create or modify a cluster, following the order assignedyou must make it match!
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

UNLESS

Clusters

If the cluster contains elements with owned labels, then the Unbundle by Name function does not need to know the ordering. This does not work with cluster constants, and has the Bundle by Name twin

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters
Original cluster control Unbundle by Namehere fully expanded, but only one element is wired.

separate control

separate indicator

Bundle by Namehere used to modify only one named element of the original cluster (names come from the cluster)
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Clusters
The rest of the cluster functions

Cluster-array conversions: shows the connection between clusters and 1-D arrays
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Error Handling & Error Clusters


By default, LabVIEW automatically handles any error that occurs when a VI runs by suspending execution, highlighting the subVI or function where the error occurred, and displaying a dialog box. You can choose other error handling methods. You can make these error handling decisions on the block diagram of the VI. VIs and functions return errors in one of two ways-with numeric error codes or with an error cluster. Typically, functions use numeric error codes, and VIs use an error cluster, usually with error inputs and outputs.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Error Handling & Error Clusters


Error handling in LabVIEW follows the dataflow model. Just as data flow through a VI, so can error information. Wire the error information from the beginning of the VI to the end. Include an error handler VI at the end of the VI to determine if the VI ran without errors. Use the error in and error out clusters in each VI you use or build to pass error information through the VI.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Error Handling & Error Clusters


As the VI runs, LabVIEW tests for errors at each execution node. If LabVIEW does not find any errors, the node executes normally. If LabVIEW detects an error, the node passes the error to the next node without executing. The next node does the same thing, and so on. Use the Simple Error Handler VI to handle the error at the end of the execution flow.

John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Error Handling & Error Clusters


(From Array & Cluster palette)

status is a Boolean value that reports True if an error occurred. Most VIs, functions, and structures that accept
Boolean data also recognize this parameter. For example, you can wire an error cluster to the Boolean inputs of the Stop, Quit LabVIEW, or Select functions. If an error occurs, the error cluster passes a True value to the function.

code is a 32-bit signed integer that identifies the error numerically. A non-zero error code coupled with a status of False signals a warning rather than a fatal error. source is a string that identifies where the error occurred.
John D. Wellin Dept. of Mechanical Engineering, RIT

EMEM 280: Measurements, Instrumentation, & Controls

Das könnte Ihnen auch gefallen