Exercise 5.7.1
Build a VI that reverses the order of an array that contains 100 random numbers. For example, array[0] becomes array[99], array[1] becomes array[98], and so on.
tip: Use the Reverse 1D Array function located on the FunctionsAll FunctionsArray palette to reverse the array order.
Save the VI as Reverse Random Array.vi in the C:\Exercises\LabVIEW Basics I directory.
Exercise 5.7.2
Build a VI that accumulates an array of temperature values using the Thermometer (Section 3.5) VI. Set the array size with a control on the front panel. Initialize an array using the Initialize Array function of the same size where all the values are equal to 10. Add the two arrays, calculate the size of the nal array, and extract the middle value from the nal array. Display the Temperature Array, Initialized Array, Final Array, and Mid Value.
Save the VI as Find Mid Value.vi in the C:\Exercises\LabVIEW Basics I directory.
Exercise 5.7.3
Build a VI that generates a 2D array of three rows by 10 columns that contains random numbers.
After generating the array, index each row, and plot each row on its own graph. The front panel should contain three graphs.
Save the VI as Extract 2D Array.vi in the C:\Exercises\LabVIEW Basics I directory.
Exercise 5.7.4
Build a VI that simulates the roll of a die with possible values 1 through 6 and records the number of times that the die rolls each value. The input is the number of times to roll the die, and the outputs include the number of times the die falls on each possible value. Use only one shift register.
Save the VI as Die Roller.vi in the C:\Exercises\LabVIEW Basics I directory.
Exercise 5.7.5
Build a VI that generates a 1D array and then multiplies pairs of elements together, starting with elements 0 and 1, and returns the resulting array. For example, the input array with values {1, 23, 10, 5, 7, 11}results in the output array {23, 50, 77}.
6This content is available online at <http://cnx.org/content/m12225/1.2/>.
7This content is available online at <http://cnx.org/content/m12226/1.3/>.
tip: Use the Decimate 1D Array function located on the FunctionsAll FunctionsArray palette.
Save the VI as Array Pair Multiplier.vi in the C:\Exercises\LabVIEW Basics I directory.
Chapter 6
Clusters
6.1 Clusters
1Clusters group data elements of mixed types, such as a bundle of wires, as in a telephone cable, where each wire in the cable represents a dierent element of the cluster. A cluster is similar to a record or a struct in text-based programming languages.
Bundling several data elements into clusters eliminates wire clutter on the block diagram and reduces the number of connector pane terminals that subVIs need. The connector pane has, at most, 28 terminals.
If a front panel contains more than 28 controls and indicators that you want to use programmatically, group some of them into a cluster and assign the cluster to a terminal on the connector pane. Like an array, a cluster is either a control or an indicator. A cluster cannot contain a mixture of controls and indicators.
Although cluster and array elements are both ordered, you must unbundle all cluster elements at once rather than index one element at a time. You also can use the Unbundle By Name function to access specic cluster elements.
6.1.1 Creating Cluster Controls and Indicators
To create a cluster control or indicator, select a cluster on the ControlsAll ControlsArray &
Cluster palette, place it on the front panel, and drag controls or indicators into the cluster shell. Re-size the cluster shell by dragging the cursor while you place the cluster shell.
The example in Figure 6.1 is a cluster of three controls.
Figure 6.1
1This content is available online at <http://cnx.org/content/m12227/1.1/>.
Available for free at Connexions <http://cnx.org/content/col10241/1.4>
6.1.2 Creating Cluster Constants
Create a cluster constant on the block diagram by selecting a cluster constant on the Cluster palette, placing it on the block diagram, and dragging a constant into the cluster shell.
If you have a cluster control or indicator on the front panel and you want to create a cluster constant containing the same elements on the block diagram, you can either drag that cluster from the front panel to the block diagram or right-click the cluster on the front panel and select CreateConstant from the shortcut menu.
6.1.3 Cluster Order
Cluster elements have a logical order unrelated to their position in the shell. The rst object you place in the cluster is element 0, the second is element 1, and so on. If you delete an element, the order adjusts automatically.
The cluster order determines the order in which the elements appear as terminals on the Bundle and Unbundle functions on the block diagram.
You can view and modify the cluster order by right-clicking the cluster border and selecting Reorder Controls In Cluster from the shortcut menu. The toolbar and cluster change, as shown in Figure 6.2.
Figure 6.2: 1. Conrm Button, 2. Cancel Button, 3. Cluster Order Cursor, 4. Current Order, 5. New Order
The white box on each element shows its current place in the cluster order. The black box shows the new place in the order for an element. To set the order of a cluster element, type the new order number in the Click to set to text box and click the element. The cluster order of the element changes, and the cluster order of other elements adjusts. Save the changes by clicking the Confirm button on the toolbar. Revert to the original order by clicking the Cancel button.
Corresponding elements, determined by the cluster order, must have compatible data types. For example, in one cluster, element 0 is a numeric control, and element 1 is a string control. In a second cluster, element 0is a numeric indicator, and element 1 is a string indicator. The cluster control correctly wires to the cluster indicator.
However, if you change the cluster order of the indicator so the string is element 0, and the numeric is element 1, the wire from the cluster control to the cluster indicator appears broken, indicating that the data types do not match.