0% found this document useful (0 votes)
12 views14 pages

LabVIEW Arrays and Clusters Guide

The document provides an overview of arrays and clusters in LabVIEW, detailing their creation, manipulation, and functions. It explains one-dimensional and two-dimensional arrays, array functions, and the operations related to clusters, including bundling and unbundling. Additionally, it includes problem-solving examples and review questions to reinforce understanding of these concepts.

Uploaded by

cathrine
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

LabVIEW Arrays and Clusters Guide

The document provides an overview of arrays and clusters in LabVIEW, detailing their creation, manipulation, and functions. It explains one-dimensional and two-dimensional arrays, array functions, and the operations related to clusters, including bundling and unbundling. Additionally, it includes problem-solving examples and review questions to reinforce understanding of these concepts.

Uploaded by

cathrine
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

4. ARRAYS
4.1 INTRODUCTION

A group of homogeneous elements of a specific data type is known as an array, one of the
simplest data structures. Arrays hold a sequence of data elements, usually of the same size and
same data type placed in contiguous memory locations that can be individually referenced.
Hence arrays are essentially a way to store many values under the same name. Individual
elements are accessed by their position in the array. The position is given by an index, which
is also called a subscript.

4.2 CREATING ONE-DIMENSIONAL ARRAY CONTROLS, INDICATORS


AND CONSTANTS

Create an array control or indicator on the front panel by placing an array shell on the front
panel and dragging a data object or element, which can be a numeric, Boolean, string, path,
refnum, or cluster control or indicator, into the array shell. The array shell automatically resizes
to accommodate the new object. The array shell can be selected from
Controls>>Modern>>Arrays, Matrix & Clusters palette. The array elements must be controls
or indicators.

Figure 4.1 Array of numeric control with index 1 selected in the index display.

4.3 CREATING TWO-DIMENSIONAL ARRAYS

A two-dimensional array is analogous to a spreadsheet or table. A two-dimensional array stores


elements in a grid. It requires a column index and a row index to locate an element, both of
which are zero-based. Two-dimensional arrays are very commonly used in data acquisition
applications.

Figure 4.2 Two-dimensional array.

26
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

4.4 ARRAY FUNCTIONS

Array functions are used to create and manipulate arrays. You can perform common array
operations such as extracting individual data elements from an array, inserting, deleting, or
replacing data elements in an array or splitting arrays using array functions.
Array functions including Index Array, Replace Array Subset, Insert Into Array, Delete
From Array, and Array Subset automatically resize to match the dimensions of the input array
you wire. For example, if you wire a one-dimensional array to one of these functions, the
function shows a single index input. If you wire a two-dimensional array to the same function,
it shows two index inputs—one for the row index and one for the column index.

Figure 4.3 (a) Index array function with one-dimensional array as input, (b) index array function with two-
dimensional array as input and with one index (row index) and (c) index array function with two-
dimensional array as input and with two indices.

27
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

4.5 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. A cluster is similar to a
record or a struct in text-based programming languages. Figure 6.1 show the error cluster
control and the corresponding terminal created in the block diagram. This cluster consists of a
Boolean control (status), a numeric control (code) and a string control (source).

Figure 4.4 Error cluster control.

Bundling several data elements into clusters eliminates wire clutter on the block diagram. It
also reduces the number of connector pane terminals that subVIs need by passing several values
to one terminal. The connector pane has, at most, 28 terminals. If your front panel contains more
than 28 controls and indicators that you want to pass to another VI, group some of them into a
cluster and assign the cluster to a terminal on the connector pane. In Figure 6.5(a) individual
values are passed to the connector pane terminals. In Figure 6.5(b) controls and indicators are
grouped into clusters and connected to one control panel terminal each.

Figure 4.5 (a) Individual values passed to subVI terminals and (b) Cluster passed to subVI
terminal.
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 as shown in Figure 4.6. You can wire brown numeric clusters to numeric

28
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

functions, such as Add or Square Root, to perform the same operation simultaneously on all
elements of the cluster.

Figure 4.6 Numeric cluster control, indicator and block diagram terminals.
4.6 CLUSTER OPERATIONS

The main cluster operations are bundle, unbundled, bundle by name and unbundle by name.
Use the cluster functions to create and manipulate clusters. For example, you can perform tasks
similar to the following:
 Extract individual data elements from a cluster.
 Add individual data elements to a cluster.
 Break a cluster out into its individual data elements.
The Bundle function assembles individual components into a single new cluster and
allows you to replace elements in an existing order. The Unbundled function splits a cluster
into its individual components. When it is required to operate on a few elements and not the
entire cluster elements, you use the Bundle By Name function. They are referenced by names
rather than by position. The Unbundle By Name function returns the cluster elements whose
names are specified.

4.7 ASSEMBLING CLUSTERS

The Bundle function assembles a cluster from individual elements as shown in Figure 4.7. You
also can use this function to change the values of individual elements in an existing cluster
without having to specify new values for all elements. To do so, wire the cluster you want to
change to the middle cluster terminal of this function. When you wire a cluster to this function,
the function resizes automatically to display inputs for each element in the cluster. The
connector pane displays the default data types for this polymorphic function. In Figure 4.8 the
input cluster consists of two numeric controls and a string control. The value of the first
numeric control is modified without altering other values.

29
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Figure 4.7 Bundling of cluster from individual elements.

Figure 4.8 Changing a value in the existing cluster.

Functions bundling elements into clusters lets you create clusters programmatically.
Complete the following steps to bundle elements into a cluster.
Step 1: Place the Bundle function on the block diagram.
Step 2: If necessary, resize the Bundle function to include the number of inputs you intend to
use as elements in the cluster. You cannot leave an input unwired.
Step 3: Wire front panel control terminals or outputs from VIs and functions to the element
inputs of the Bundle function. The order in which you wire the inputs determines the cluster
element order.
Step 4: Right-click the Output Cluster terminal and select Create»Indicator. LabVIEW returns
the bundled cluster in the cluster output.
4.8 DISASSEMBLING CLUSTERS

The Unbundle function splits a cluster into each of its individual elements. When you wire a
cluster to this function, the function resizes automatically to display outputs for each element
in the cluster you wired as shown in Figure 4.9. The connector pane displays the default data
types for this polymorphic function. The data type representation of every element appears as
element outputs.

30
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Figure 4.9 Unbundle function and Unbundle By Name function.

4.9 CONVERSION BETWEEN ARRAYS AND CLUSTERS

LabVIEW has many more functions for arrays than clusters and it is often required to change
array to clusters and clusters to arrays. A cluster can be converted into an array first and
converted back to a cluster after performing the required operation from the available array
functions. You can convert a cluster with elements of the same data type to an array using the
Cluster To Array function as shown in Figure 4.10 and use array functions to manipulate the
contents. This function cannot be used on a cluster of arrays, since LabVIEW does not allow
an array or arrays type of structure.

Figure 4.10 Converting a cluster into an array.

You can convert a cluster with elements of the same type to an array and use array
functions to manipulate the contents. Complete the following steps to convert a cluster to an
array.
Step 1: Place a cluster on the front panel.
Step 2: Place the Cluster To Array function on the block diagram.

31
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Step 3: Wire the cluster to the Cluster To Array function.


Step 4: Right-click the Cluster To Array function and select Create»Indicator from the
shortcut menu to create an array indicator.
Step 5: Run the VI from the front panel. The array indicator displays the values of the cluster.

4.10 ERROR HANDLING

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. For example, if an I/O
VI on the block diagram times out, you might not want the entire application to stop. You also
might want the VI to retry for a certain period of time. In LabVIEW, 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. Error handling in LabVIEW follows the data flow model.
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, shown in Figure 6.12, to handle the error at the end of the
execution flow. The simple error handler VI is located on the Functions»All Functions»Time
& Dialog palette. Wire the error cluster to the error in input.

Figure 4.11 Simple error handler.

32
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

MISCELLANEOUS SOLVED PROBLEMS


Problem 4.1 Create a one-dimensional (1D) numeric array using the Build Array function which gets
array elements from numeric controls.
Solution The front panel and the block diagram to create a one-dimensional (1D) numeric array are
shown in Figures P4.1(a) and P4.1(b).

Figure P4.1
Problem 4.2 Create a 1D numeric array from loops (For and While) using random numbers and obtain
the reverse of the array.
Solution The front panel and the block diagram to create a 1D numeric array from loops are shown in
Figures P4.2(a) and P4.2(b).

Figure P4.2

33
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Problem 4.3 Create a VI to find the determinant of a 2 x 2 matrix which is represented in the form of a
2D array using Index array function.
Solution Build the front panel and the block diagram to find the determinant of a 2 x 2 matrix are shown in
Figures P4.3(a) and P4.3(b).

Figure P4.3

Problem 4.4 Create a 1D numeric array which consists of ten elements and rotate it ten times. For each
rotation display the equivalent binary number of the first array element in the form of a Boolean array. Also
display the reversed Boolean array. Provide delay to view the rotation.
Solution The front panel and the block diagram to build a 1D numeric array are shown in Figures P4.4(a)
and P4.4(b).

34
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Figure P4.4

Problem 4.5 Create a 2D numeric array (5 x 5) containing random numbers and find its transpose.
Solution The front panel and the block diagram to build a 2D numeric array are shown in Figures P4.5(a)
and P4.5(b).

Figure P4.5

35
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Problem 4.6 Create two 2D numeric arrays and add them. Change the number of rows and number of
columns of each array and see the result.
Solution The front panel and the block diagram to solve the problem are shown in Figures P4.6(a) and
P4.6(b).

Figure P4.6

Problem 4.7 Build a VI to find the product of two matrices using matrix function.
Solution Create the front panel and the block diagram to solve the problem as shown in Figures P4.7(a)
and P4.7(b).

Figure P4.7

36
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Problem 4.8 Create a VI to add a value with every element of an available cluster. (Adding a numeric to a
cluster results in the addition of the numeric to each element in the cluster.)
Solution To solve the problem build the front panel and the block diagram as shown in Figures
P4.8(a) and P4.8(b).

Figure P4.8

Problem 4.9 Create a VI consisting of two clusters of LEDs. Perform the AND operation between the clusters
and display the output in another cluster of LEDs. (When comparing clusters, the And function compares
each element with its corresponding value in the second cluster.)
Solution Build the front panel and the block diagram as shown in Figures P4.9(a) and P4.9(b) to solve the
problem.

Figure P4.9

37
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

Problem 4.10 Create a VI to compare the elements of two clusters. If the values of corresponding elements
of both the VIs are the same, switch ON an LED in the output cluster.
Solution The front panel and the block diagram to solve the problem are shown in Figures P4.10(a) and
P4.10(b).

Figure P4.10

Problem 4.11 Create a VI to select between two input clusters using a toggle switch and display in an output
cluster.
Solution Build the front panel and the block diagram as shown in Figure P4.11(a) and P4.11(b) to solve the
problem.

Figure P4.11

REVIEW QUESTIONS
1. Define an array in LabVIEW. Where might it be used?
2. What is an array indexing?
3. How are the individual elements accessed and processed in an array?
4. What is array initialization?
5. What is multidimensional array? How is it different from one-dimensional array?
6. How are the individual elements of a multidimensional array accessed and processed?
7. How to create a two-dimensional array of numeric controls?
8. How can a loop create an array? Which loops can be used to do so?
9. Define auto-indexing.

10. What is the function of a cluster?


11. Differentiate an array from a cluster.
12. Explain how clusters can reduce the number of terminals of a subV.I.

38
ECE Department: Skill Oriented Course Graphical System Design Using LabVIEW

13. What is cluster order? Explain why it is important.


14. What is the difference between a Bundle and Bundle By Name functions?
15. Explain the method of changing the value of an element in an existing cluster.
16. Explain the use of error clusters with the help of an example.
17. With the help of an example explain assembling and disassembling clusters.

EXERCISES
1. Create a 1D Boolean array and obtain the reverse of the array.
2. Create a 1D numeric array and check whether the array elements are odd or even. In the output array
display 0s and 1s for odd numbers and even numbers respectively.
3. Create a VI to generate random numbers between 0–50, 50–100, 0–100 and put then into separate
arrays.
4. Build a VI that generates a 1D array of random numbers and sort the array in ascending and descending
order and find the maximum and minimum value of the array elements and also find the size of the
array.
5. Create a VI to read a set of numbers from the keyboard and sort them in ascending order.
6. Create a VI to read a set of numbers from the keyboard and find the sum of the array elements.
7. Create a VI to pick up the largest number from any 5 x 5 matrix.
8. Create a VI to obtain the transpose of a 4 x 4 matrix. The transpose of a matrix is obtained by
exchanging the elements of each row with the elements of the corresponding column.
9. Create a VI to read the integer number and find out the sum of all the digits until it comes to a single
digit using an array.
For example: n = 1346
Sum = 1 + 3 + 4 + 6 = 14
Sum = 1 + 4 = 5
10. Build a cluster control which consists of a thermometer, a tank and a gauge. Build a cluster constant
which consists of a scaling factor for all the three cluster controls. Display the scaled values in a
cluster indicator.
11. Create a cluster which consists of a numeric control, two Boolean controls and a slide control.
Modify the values of the cluster control and display them in a cluster indicator.
12. In Problem 6.8 change the 1D numeric array into 2D numeric array. The 2D array is to provide
marks obtained in three tests.

39

Common questions

Powered by AI

LabVIEW uses arrays to manage sequences of homogeneous data elements, allowing them to be stored in contiguous memory locations and accessed via indices. Clusters, on the other hand, group heterogeneous data elements, similar to records or structs in text-based languages. This grouping facilitates structured data management and reduces terminal clutter by passing multiple values through a single terminal . Conversion between arrays and clusters can be achieved by using the Cluster To Array function for clusters with elements of the same data type. This enables users to apply array functions to manipulate data and then convert back, if necessary . These conversions enhance flexibility, allowing engineers to utilize the extensive array functions available in LabVIEW.

Manually creating a two-dimensional numeric array in LabVIEW involves placing individual numeric controls into an array shell on the front panel, configuring its size, and entering values directly . This method is straightforward for small, static arrays but loses efficacy with larger or dynamic datasets. Contrastingly, loop-based creation employs iteration control, such as For Loops, to populate arrays programmatically. Auto-indexing on loop boundaries facilitates dynamic construction by iterating over data sources or mathematical functions, leading to scalable solutions that better adapt to variable dataset sizes and inputs . This distinction highlights loops' superior scalability and adaptability, counterbalanced by manual setup's straightforward but limited application scope.

The Bundle function in LabVIEW is used to assemble a cluster from individual components, either creating new clusters or modifying existing ones without altering unspecified elements. This can be particularly useful when updating a subset of elements in a cluster . The Bundle By Name function, however, allows for a more targeted approach by operating on cluster elements specifically by their names rather than their positional index. This specificity reduces errors and adds clarity especially in large clusters, as it is more intuitive to use names than numeric indices when modifying cluster contents . These capabilities are essential for precise data manipulation, enhancing code readability and maintenance.

The error cluster in LabVIEW consolidates Boolean, numeric, and string data types into a single structured form, which simplifies the connector pane by bundling multiple error-related terminals into one. This approach eliminates wire clutter and reduces the number of connections necessary for error handling . Effective design strategies involve using error clusters consistently across VIs, integrating them into data flow logic, and applying them at key decision points to dictate program behavior in the presence of errors. Utilizing built-in error handling VIs and functions allows for systematic capturing and processing of errors, promoting modular, maintainable code.

LabVIEW's default error handling suspends execution when an error occurs, highlighting the offending subVI or function and displaying a dialog box . However, programmers can implement more sophisticated strategies, such as configuring VIs to retry processes upon encountering errors, use timeouts, and redirect data flow based on error conditions. Errors are typically reported via numeric codes or error clusters, the latter being more versatile as they carry comprehensive error-related data . In practical applications, programmers might make use of error clusters in flow control to ensure robust error management across VIs, preventing common issues like unexpected halts, and allowing for seamless user experiences even when errors emerge.

The Simple Error Handler VI in LabVIEW provides a standardized method for addressing errors across applications by accepting error clusters as input and offering various response strategies. It effectively consolidates error information, thereby enhancing flow control efficiency by clearly delineating points of failure within the data flow model . By displaying dialogue boxes and potentially redirecting execution based on error states, it simplifies the implementation of robust error management protocols. This tool forms the backbone of coherent error handling strategies in complex applications, helping developers quickly identify and address error origins without extensive custom error management systems.

Auto-indexing in LabVIEW is a feature that automatically constructs arrays from the elements generated in each iteration of a loop. When a loop boundary terminal is auto-indexed, the elements processed in each iteration are accumulated into a single array, transforming element-wise operations into array-wide processes without additional code . This feature is especially useful in scenarios requiring dynamic array generation or manipulation, such as accumulating data from real-time measurements. Utilizing auto-indexing simplifies code by eliminating manual array size declarations and concatenations, streamlining development and enhancing code readability.

The Index Array function in LabVIEW is crucial for accessing specific elements within arrays. For one-dimensional arrays, it allows users to extract individual elements using a single index. For two-dimensional arrays, it accommodates two indices—row and column—to access grid-like structures, akin to spreadsheets or matrices . The dual-index mechanism in two-dimensional arrays enables access to both row-major and column-major formats, facilitating complex data handling in applications like data acquisition and matrix computations . By resizing automatically to match input array dimensions, this function efficiently provides flexibility and reduces manual configuration, essential for dynamic data processing environments.

The Unbundle By Name function allows programmers to extract specific elements from a cluster using their assigned names, rather than relying on position indices as in the standard Unbundle function. This approach significantly enhances code readability by allowing developers to interact with descriptive names that convey meaning and context . As a result, it reduces the risk of errors associated with misinterpreting index positions. Thus, using Unbundle By Name supports better code maintenance and reduces debugging challenges, contributing to clearer and more intuitive data management within clusters.

In LabVIEW, cluster order refers to the sequence in which elements are stored and accessed within a cluster. This order is critical because it affects how elements are bundled and unbundled, especially when using functions that don't operate by element name, like the basic Bundle and Unbundle functions . Altering the cluster order can lead to unexpected results if data elements are repositioned, as subsequent operations might rearrange data unintentionally. Thus, maintaining a consistent order is crucial for coherent data processing, and ordering should be explicitly managed when modifying or extending clusters to ensure processing logic remains valid.

You might also like