Polymorphism


Another handy feature you'll find useful is the polymorphism of the LabVIEW arithmetic functions, Add, Multiply, Divide, and so on. Polymorphism is just a big word for a simple principle: the inputs to these functions can be of different size and representation. For example, you can add a scalar to an array or add two arrays together using the same function. Figure 7.33 shows some of the polymorphic combinations of the Add function.

Figure 7.33. Some of the polymorphic combinations of the Add function


In the first combination, the result is a scalar number. In the second combination, the scalar is added to each element of the array. In the third combination, each element of one array is added to the corresponding element of the other array. The same Add function is used in all instances, but it performs a different type of operation in each.

In Figure 7.34, each iteration of the For Loop generates one random number (valued between 0 and 1) that is stored in the array created at the border of the loop. After the loop finishes execution, the Multiply function multiplies each element in the array by the scaling factor you set. The front panel array indicator then displays the scaled array.

Figure 7.34. Multiplying a 1D numeric array by a scalar numeric value


Figure 7.35 shows some of the possible polymorphic combinations of the Add function. You'll learn about the clusters it depicts in the next section.

Figure 7.35. Some possible polymorphic combinations of the Add function


If you are doing arithmetic on two arrays with a different number of elements, the resulting array will be the size of the smaller of the two. In other words LabVIEW operates on corresponding elements in the two arrays until one of the arrays runs out of elements. The remaining elements in the longer array are ignored.


In addition to functions that are polymorphic, VIs can be polymorphic too. A polymorphic VI is a special type of VI that is actually a group of VIs, each VI handling a different data type. You can even create your own polymorphic VIs. You will learn more about polymorphic VIs in Chapter 13, "Advanced LabVIEW Structures and Functions."





LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net