Two-Dimensional Arrays


A two-dimensional, or 2D, array stores elements in a grid-like fashion. It requires two indices to locate an element: a column index and a row index, both of which are zero-based like everything else in LabVIEW. Figure 7.12 shows how a six-column by four-row array that contains six times four elements is represented.

Figure 7.12. Six-column by four-row array of 24 elements


You can add dimensions to an array control or indicator by popping up on its index display (not on the element display) and choosing Add Dimension from the pop-up menu. Figure 7.13 shows a 2D array of digital controls. Notice that you now have two indices to specify each element. You can use the Positioning tool to expand your element display in two dimensions so that you can see more elements, by hovering the mouse over the array shell until the resizing handles appear and then dragging the resizing handles.

Figure 7.13. 2D array of digital controls


Remove unwanted dimensions by selecting Remove Dimension from the index display's pop-up menu.

Creating Two-Dimensional Arrays

You can use two For Loops, one inside the other, to create a 2D array if you don't want to type in values on the front panel. The inner For Loop creates a row, and the outer For Loop "stacks" these rows to fill in the columns of the matrix. The illustration in Figure 7.14 shows two For Loops creating a 2D array of random numbers using auto-indexing.

Notice that a 2D array wire is even thicker than a 1D array wire.

Figure 7.14. Two For Loops creating a 2D array using auto-indexing





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