Confused yet? You'll get a better feel for arrays as you work with them. In this exercise, you will finish building a VI that concatenates two arrays and then indexes out the element in the middle of the new concatenated array. | | 1. | Open Array Exercise.vi, located in EVERYONE\CH07.
The front panel contains two input arrays (each showing three elements), two digital controls, and an output array (showing eight elements). The VI will concatenate the arrays and the control values in the following sequence to create the new array.
Initial Array + Element 1 + Element 2 + Terminal Array
The front panel is already built. You will finish building the diagram. Note that an array control or indicator will appear grayed out until you or the program assigns it some data (see Figure 7.31).
Figure 7.31. Array Excersise.vi front panel | 2. | Build the block diagram in Figure 7.32. Use the Help window to find the correct terminals on the functions.
Figure 7.32. Array Exercise.vi block diagram | Build Array Function Build Array function (Programming>>Array palette). In this exercise, concatenates the input data to create a new array in the following sequence: Initial Array + Element 1 + Element 2 + Terminal Array. Build Array Function The function looks like the icon at the left when placed in the diagram window. Place the Positioning tool on the lower-middle edge and resize the function with the resize handles until it includes four inputs. Array Input Element Input The inputs will automatically detect whether you are wiring an array or an element. The symbols at the left indicate whether an input is an array or an element. Array Size Function Array Size function (Programming>>Array palette). Returns the number of elements in the concatenated array. Index Array Function Index Array function (Programming>>Array palette). In this exercise, returns the element in the middle of the array. LabVIEW builds the array using the Build Array function, and then calculates the index for the middle element of the array by taking the length of the array, dividing it by two, and subtracting one (to account for the zero-based array index). Because the array has an even number of elements, the middle element will actually be one of the two middle elements.
Notice those coercion dots? You can't get rid of them simply by changing the two constants to I32s, because the Divide function coerces them back in order to handle fractional outputs. But if you replace the Divide with the Quotient & Remainder (right next to it on the Numeric palette), the dots will go away. Because the Quotient output is a floor function, you no longer need the Subtract. | 3. | Return to the front panel and run the VI. Try several different number combinations.
| 4. | Save the finished VI in your MYWORK directory and close the VI.
| You might also want to look through the programs in EXAMPLES/GENERAL/ARRAYS.LLB in the LabVIEW directory, to see some other things you can do with arrays. These examples can be easily found using the NI Example Finder (from the Help>>Find Examples menu) by selecting Browse according to: Directory Structure and then navigating the tree control to general/arrays.llb. |