LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
Sometimes you will find it convenient to change arrays to clusters, and vice versa. This trick can be extremely useful, especially because LabVIEW includes many more functions that operate on arrays than clusters. For example, maybe you have a cluster of buttons on your front panel and you want to reverse the order of the buttons' values. Well, Reverse 1D Array would be perfect, but it only works on arrays. Have no fearyou can use the Cluster To Array function to change the cluster to an array, use Reverse 1D Array to switch the values around, and then use Array To Cluster to change back to a cluster (see Figures 7.60 and 7.61). Figure 7.60. Array To Cluster
Figure 7.61. Cluster To Array
Cluster To Array converts a cluster of N elements of the same data type into an array of N elements of that type. Array index corresponds to cluster order (i.e., cluster element 0 becomes the value at array index 0). You cannot use this function on a cluster containing arrays as elements, because LabVIEW won't let you create an array of arrays. Note that all elements in the cluster must have the same data type to use this function. Array To Cluster converts an N element, 1D array into a cluster of N elements of the same data type; you must pop up on the Array To Cluster terminal and choose Cluster Size... to specify the size of the output cluster because clusters don't size automatically like arrays do. The cluster size defaults to 9; if your array is not empty but has fewer than the number of elements specified in the cluster size, LabVIEW will automatically fill in the extra cluster values with the default value for the data type of the cluster. However, if the input array has a greater number of elements than the value specified in the cluster size window, the input array will be truncated (trimmed) to the number of elements specified in the cluster size. It is also important that the output cluster size match the number of elements of the data sink to which it is wiredif it does not match, the output wire will be broken until the cluster size is adjusted appropriately. Both functions are very handy if you want to display elements in a front panel cluster control or indicator but need to manipulate the elements by index value on the block diagram. They can be found in both the Programming>>Array and Programming>>Cluster & Variant subpalettes of the Functions palette. Comparison Function Modes for Arrays and Clusters
Some Comparison functions have two modes for comparing arrays or clusters of data: Compare Aggregates mode and Compare Elements mode. You can select the mode you want from the Comparison Mode submenu of the comparison node's pop-up menu (shown in Figure 7.62). Figure 7.62. Selecting the Comparison Mode of the polymorphic Add function
In Compare Aggregates mode, the Comparison functions return a single Boolean value that is a comparison of the entire aggregatethe returned Boolean is TRUE if and only if the comparison is TRUE for all elements. In Compare Elements mode, the Comparison functions return an array or cluster of Boolean values, which is a comparison of the individual elements, on a per-element basis. Figure 7.63 shows an example of these two different comparison modes with the Add function. Figure 7.63. The two different modes of the polymorphic Add function: Compare Elements (left) and Compare Aggregates (right)
|
Категории