Section 7 Activity 7-1: Building Arrays with Auto-Indexing 练习7-1:用自动索引创建数组
推荐给好友
打印
加入收藏
更新于2008-05-16 19:33:46

Activity 7-1: Building Arrays with Auto-Indexing

练习7-1:用自动索引创建数组

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.

接下来我们将给你一个自己操作的机会来更好的理解数组和自动索引功能。在本练习中,你将打开和观察一个利用自动索引的for循环和while循环来创建数据数组。

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).

1.打开光盘中EVERYONE\CH07目录下创建数组VI。这个例子在前面板创建了两个数组,用for循环和while循环分别产生一个二维数组和一个一维数组。For循环执行固定的次数,while循环则要通过STOP按钮来停止(或者执行完101次后停止)。

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.

2. 观看前面板(见图7.15),然后框图(见图7.16)。注意嵌套的for循环在边界处使用自动索引分别产生二维数组的行和列。同时注意自动索引的连线从for循环边界出来后变粗的现象。

Figure 7.15. Building Arrays.vi front panel

图7.15 创建数组前面板

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.

3. 在从while循环得到数组数据输出之前,先要点击包含随机数字的隧道端子在弹出菜单中选择允许索引。欲知具体自动索引怎么工作,再点击隧道端子选择禁止索引,此时会看到从for循环出来的线变成了断线。点击端子允许索引修复它即可。

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.

这个循环用了一个逻辑算法使得用户不需手动点STOP按钮即可让程序在合理运行次数(101次循环)后退出循环。用户没有按钮STOP按钮并且循环次数没有到101次之前,程序持续运行。这两个条件中任一个改变都可以停止循环。

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).

为什么循环执行101次而不是100次呢?记住,while循环是在每次循环之后检查条件端子的大小,第100次循环结束时,i的值为99(从0开始)小于100,循环还继续执行。当第101次执行完后,计数端子的值不再小于100此时循环中止(假设STOP键没有被按下)。

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).

4.在理解这些之后,运行VI。记得要点击STOP中止while循环,因为前面板板指示器会在整个数组创建之后才会更新显示(记住,在循环运行时,读不到循环外的控制器的值,指示器的值也不能更新)。

5. Close the VI and don't save any changes.

5.关闭VI,不保存任何改变。

 

<<PREV    NEXT>>




 
关于我们 | 诚邀加盟 | 客户服务 | 相关法律 | 网站地图 | 友情链接 | 服务信箱:service@eefocus.com
© 2006 与非门科技信息咨询(北京)有限公司 All Rights Reserved.