Activity 7-1: Building Arrays with Auto-Indexing


Now we'll give you a chance to better understand arrays and auto-indexing by working with them yourself. In this activity, you will open and observe a VI that uses auto-indexing on both a For Loop and a While Loop to create arrays of data.

1.

Open the Building Arrays.vi example, located in EVERYONE\CH07. This exercise generates two arrays on the front panel, using a For Loop to create a 2D array and a While Loop to create a 1D array. The For Loop executes a set number of times; you must hit the STOP button to halt the While Loop (or it will stop after 101 iterations).

2.

Take a look at the front panel (see Figure 7.15), and then switch to the block diagram (see Figure 7.16). Notice how the nested For Loops create a 2D array's rows and columns at their borders, respectively, using auto-indexing. Also notice how the auto-indexed wires become thicker as they leave the loop boundaries.

Figure 7.15. Building Arrays.vi front panel


Figure 7.16. Building Arrays.vi block diagram


3.

Before we could get array data out of the While Loop, we had to pop up on the tunnel containing the random number and Select Enable Indexing. To see how this works, go ahead and pop up on the tunnel, then select Disable Indexing. You will see the wire leaving the Loop break. Pop up on the tunnel again and select Enable Indexing to fix it.

This loop uses a little logic algorithm to ensure that if the user does not press the STOP button after a reasonable amount of time (101 iterations), the loop stops anyway. If the user has not pressed the STOP button AND the loop has executed fewer than 101 times, the loop continues. If either of those conditions changes, the loop stops.

Why does it execute 101 times, instead of 100? Remember that the While Loop checks the conditional terminal at the end of each iteration. At the end of the 100th iteration, i 99 (because it starts at zero), which is less than 100, and the loop continues. At the end of the 101st iteration, the count is no longer less than 100 and the loop stops (assuming the STOP button hasn't already stopped it).

4.

Now that you understand how it works, run the VI. Remember to hit STOP to halt the While Loop, especially because the front panel indicator does not update until the entire array has been generated (remember, controls and indicators outside loops are not read or updated while the loop is executing).

5.

Close the VI and don't save any changes.




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