Overview
This exercise will go over how to create arrays and clusters. You will also learn about how to pass data to and from arrays and how to bundle and unbundle clusters.
Goal
Understand the basic behavior of arrays and clusters in the LabVIEW environment.
Description
This exercise consists of a series of tasks in which will walk you through how data is passed to and from arrays. Indexing arrays will be explored in detail. How to bundle data will be explained as well as how to unbundle information from clusters.
Arrays
Description
You are given a VI and asked to enhance it for a variety of purposes. For each part of this exercise, begin with the Array Investigation.vi located at the bottom of this page. The front panel of this VI is shown in the figure below.

The next figure shows the block diagram of this VI.

This exercise is divided into parts. You are given the scenario for each part first. Refer to the end of this exercise for detailed implementation instructions for each part.
Part 1: Iterate, Modify, and Graph Array
Modify the Array Investigation VI so that after the array is created, the array is indexed into For Loops where you multiply each element of the array by 100 and coerce each element to the nearest whole number. Graph the resulting 2D array to an intensity graph.
Part 2: Simplified Iterate, Modify, and Graph Array
Modify the Array Investigation VI or the solution from Part 1 to accomplish the same goals without using the nested For Loops.
Part 3: Create Subset Arrays
Modify the Array Investigation VI so that the VI creates a new array that contains the contents of the third row, and another new array that contains the contents of the second column.
Part 1: Implementation
Modify the Array Investigation VI so that after the array is created, the array is indexed into For Loops where you multiply each element of the array by 100 and coerce each element to the nearest whole number. Graph the resulting 2D array on an intensity graph.
1. Open Array Investigation.vi located at the bottom of this page.
2. Save the VI as Array Investigation Part 1.vi.
3. Add an intensity graph to the front panel of the VI and autoscale the X and Y axes, as shown in the figure below. To autoscale the axes, right-click the intensity graph and select X Scale»AutoScale X and Y Scale»AutoScale Y.

- Open the block diagram of the VI.
In the following steps, you create a block diagram similar to the next figure.
5. Iterate the Array.
❑ Add a For Loop to the right of the existing code.
❑ Add a second For Loop inside the first For Loop.
❑ Wire the array indicator terminal to the interior For Loop border. This creates an auto-indexed input tunnel on both For Loops.
6. Multiply each element of the array by 100.
❑ Add a Multiply function to the interior For Loop.
❑ Wire the indexed input tunnel to the x input of the Multiply function.
❑ Right-click the y input and select Create»Constant from the shortcut menu.
❑ Enter 100 in the constant.
7. Round each element to the nearest whole number.
❑ Add a Round To Nearest function to the right of the Multiple function.
❑ Wire the output of the Multiply function to the input of the Round To Nearest function.
8. Create a 2D array on the output of the For Loops to recreate the modified array.
❑ Wire the output of the Round To Nearest function to the outer For Loop. This creates an auto-indexed output tunnel on both For Loops.
9. Wire the output array to the Intensity Graph indicator.
10. Switch to the front panel.
11. Save the VI.
12. Enter values for Rows and Columns.
13. Run the VI.
Part 2: Implementation
Modify Part 1 to accomplish the same goals without using the nested For Loops.
1. Open Array Investigation Part 1.vi if it is not still open.
2. Save the VI as Array Investigation Part 2.vi.
3. Open the block diagram.
4. Right-click the border of the interior For Loop, containing the Multiply function and the Round to Nearest function, and select Remove For Loop.
5. Right-click the border of the remaining For Loop and select Remove For Loop from the shortcut menu. Your block diagram should resemble the figure below.
6. Save the VI.
7. Switch to the front panel.
8. Enter values for Rows and Columns.
9. Run the VI.
Notice that the VI behaves the same as the solution for Part 1. This is because mathematical functions are polymorphic. For example, because the x input of the Multiply function is a two-dimensional array, and the y input is a scalar, the Multiply function multiplies each element in the array by the scalar, and outputs an array of the same dimension as the x input.
Part 3: Implementation
Modify Array Investigation VI so that the VI creates a new array that contains the contents of the third row, and another new array that contains the contents of the second column.
1. Open Array Investigation.vi located at the bottom of this page
2. Save the VI as Array Investigation Part 3.vi.
3. Open the block diagram of the VI.
In the following steps, you build a block diagram similar to that shown in the next figure.
4. Retrieve the third row of data from Array using the Index Array function.
❑ Add the Index Array function to the block diagram.
❑ Wire Array to the array input of the Index Array function.
Tip: The Index Array function accepts an n-dimensional array. After you wire the input array to the Index Array function, the input and output terminal names change to match the dimension of the array wired. Therefore, wire the input array to the Index Array function before wiring any other terminals.
❑ Right-click the index(row) input of the Index Array function.
❑ Select Create»Constant from the shortcut menu.
❑ Enter 2 in the constant to retrieve the third row. Remember that the index begins at zero.
❑ Right-click the subarray output of the Index Array function.
❑ Select Create»Indicator from the shortcut menu.
❑ Name the indicator Third Row.
5. Retrieve the second column of data from the Array using the Index Array function.
❑ Add another Index Array function to the block diagram.
❑ Wire Array to the array input of the Index Array function.
❑ Right-click the disable index(col) input of the Index Array function.
❑ Select Create»Constant.
❑ Enter 1 in the constant to retrieve the second column because the index begins at zero.
❑ Right-click the subarray output of the Index Array function.
❑ Select Create»Indicator.
❑ Name the indicator Second Column.
6. Save the VI.
7. Switch to the front panel.
8. Enter values for Rows and Columns.
9. Run the VI.
Clusters
1. Open a blank VI.
2. Save the VI as Cluster Experiment.vi .
In the following steps, you create a front panel similar to the figure below.

3. Add a Stop button to the front panel window.
4. Add a Numeric indicator to the front panel window.
5. Add a Round LED to the front panel.
6. Rename the LED Boolean 2.
7. Create a cluster named Cluster, containing a numeric control, two toggle switches, and a slide control.
❑ Add a Cluster Shell to the front panel.
❑ Add a Numeric control to the cluster.
❑ Add two Vertical Toggle Switches to the cluster.
❑ Rename the Boolean toggle switches to Boolean 1.
❑ Add a Horizontal Fill Slide to the cluster.
8. Create Modified Cluster, containing the same contents as Cluster, but indicators instead of controls.
❑ Create a copy of Cluster.
❑ Relabel the copy Modified Cluster.
❑ Right-click the shell of Modified Cluster, and select Change to Indicator from the shortcut menu.
9. Create Small Cluster, containing a Boolean indicator and a numeric indicator.
❑ Create a copy of Modified Cluster.
❑ Relabel the copy Small Cluster.
❑ Delete the second toggle switch.
❑ Delete the horizontal fill slide indicator.
❑ Right-click Small Cluster and select Autosizing»Size to Fit.
❑ Relabel the numeric indicator to Slide value.
❑ Resize the cluster as needed.
10. Verify the cluster order of Cluster, Modified Cluster, and Small Cluster.
❑ Right-click the boundary of Cluster and select Reorder Controls in Cluster from the shortcut menu.
❑ Confirm the cluster order shown in the figure below.
❑ Click the Confirm button on the toolbar to set the cluster order and exit the cluster order edit mode.
❑ Right-click the boundary of Modified Cluster and select Reorder Controls in Cluster from the shortcut menu.
❑ Confirm the cluster orders shown in the figure below. Modified Cluster should have the same cluster order as Cluster.
❑ Click the Confirm button on the toolbar to set the cluster order and exit the cluster order edit mode.
❑ Right-click the boundary of Small Cluster and select Reorder Controls in Cluster from the shortcut menu. Click the OK button on the toolbar to set the cluster order and exit the cluster order edit mode.
❑ Confirm the cluster orders shown in the figure below.

In the following steps, build the block diagram shown in the next figure.

11. Add the While Loop from the Structures palette to the block diagram.
- Disassemble Cluster.
❑ Add the Unbundle function to the block diagram.
❑ Wire Cluster to the input of the Unbundle function to resize the function automatically.
13. Assemble Small Cluster.
❑ Add the Bundle function to the block diagram.
❑ Wire the Bundle function as shown in the figure above.
14. Assemble Modified Cluster.
❑ Add the Unbundle by Name function to the block diagram.
❑ Wire the Cluster to the Unbundle by Name function.
❑ Resize the Unbundle by Name function to have two output terminals.
❑ Select Numeric in the first node, and Boolean 1 in the second node. If a label name is not correct, use the Operating tool to select the correct item.
❑ Add the Increment function to the block diagram.
❑ Wire the Numeric output of the Unbundle By Name function to the input of the Increment function. This function adds one to the value of Numeric.
❑ Add the Not function to the block diagram.
❑ Wire the Boolean 1 output of the Unbundle By Name function to the x input of the Not function. This function returns the logical opposite of the value of Boolean.
❑ Add the Bundle by Name function to the block diagram.
❑ Wire Cluster to the input cluster input.
❑ Resize this function to have two input terminals.
❑ Select Numeric in the first node and Boolean 1 in the second node. If a label name is not correct, use the Operating tool to select the correct item.
❑ Wire the output of the Increment function to Numeric.
❑ Wire the output of the Not function to Boolean 1.
❑ Wire the output of the Bundle By Name function to the Modified Cluster indicator.
15. Add a wait function to provide the processor with time to complete other tasks.
❑ Add the Wait Until Next ms Multiple function to the block diagram.
❑ Right-click the millisecond multiple terminal of the Wait Until Next ms Multiple function.
❑ Select Create»Constant from the shortcut menu.
❑ Enter 100 in the constant.
16. Complete the block diagram and wire the objects as shown in the previous figure.
17. Save the VI.
18. Display the front panel.
19. Run the VI.
20. Enter different values in Cluster and notice how values entered in Cluster affect the Modified Cluster and Small Cluster indicators. Is this the behavior you expected?
21. Click the Stop button when you are done.
22. Change the cluster order of Modified Cluster. Run the VI. How did the changed order affect the behavior?
23. Close the VI. Do not save changes.
Tutorial Video Arrays, Clusters, and Text Based Nodes Modules Home FIRST Community
Downloads
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).



