Presentation is loading. Please wait.

Presentation is loading. Please wait.

EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.

Similar presentations


Presentation on theme: "EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3."— Presentation transcript:

1 EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
Homework #9 and Lab #9 due next week. Quiz #5 next week -In programs written up to now, controls, indicators, and wires have held only one value at a time. Arrays and clusters let you group together many values in a control, indicator, or wire. -On Notification example note difference in thickness of 2 pink lines from sequence structure. Also note array of simulated temp values on block diagram of Simulated Temp.vi

2 Arrays and Clusters An array is a variable-sized collection of data elements that are all of the same data type (such as floating point, integer, string, or Boolean). A cluster is a fixed-sized collection of data elements of mixed data types. (Bishop, p. 289)

3 Usefulness of Arrays Arrays are useful when you have a collection of data points that you wish to plot or a collection of similar items that you wish to manipulate as a group. (Bishop, p. 289)

4 Dimension of an Array Every array has a dimension.
The simplest arrays are one-dimensional arrays, which you can think of as a list of items. Example: a list of student grades on a single assignment in a class: 90, 77, 82, 95, 60, : (Bishop, p. 289) -In this example, each item represents the grade of a different student. You can refer to any item in the list by its position in the list. -Suppose you want to find average grade and max and min grades on an assignment. Without using arrays, you’d need one numeric control for each student, and then wire them together using math functions. -Demo this for five students.

5 Creating an Array of Controls or Indicators
To create an array of controls or indicators: Place an array shell on the front panel from the Controls >> Modern >> Array, Matrix & Cluster palette. Place a control or indicator inside that array shell. We’ll see that you can also create arrays using block-diagram functions. -Demo creating an array of numeric controls.

6 Displaying Multiple Elements
To display more than one element of an array on the front panel, drag the array’s resizing handles until the desired number of elements are visible. The box to the left shows the index of the first visible element. (Bishop, p. 290) -Demo by typing in values to numeric controls, and then show how easy it is to find average (using Add Array on Numeric palette), max, and min(using Max&Min on Arrays palette).

7 Index of an Element Each element in an array can be referred to by its index, which is an integer showing the element’s position in the array. In LabVIEW, indexes are zero-based. So the first element in a one-dimensional array has an index of 0, the second element has an index of 1, and so on. If a one-dimensional array contains n elements, the last element has an index of n1. (Bishop, p. 289) For a two-dimensional array, the index is a pair of numbers identifying the item’s row and column.

8 Array Terminal on Block Diagram
When an array shell is first created, its terminal on the block diagram is outlined in black and shows no data type. After the array’s data type has been defined by placing an item in the shell, the terminal changes color to show the data type. (Bishop, p. 292)

9 Array Wires on Block Diagram
On the block diagram, a wire carrying an array of data values is thicker than a wire carrying a single data value. (Bishop, p. 292) Demo by wiring a single toggle switch to a single LED, and then wiring an array of toggle switches to an array of LEDs.

10 Arrays & the DAQ Assistant
When you use the DAQ Assistant to perform digital input, the DAQ Assistant produces an array of Boolean values. And when you use it to perform digital output, you must provide the DAQ Assistant with an array of Boolean values. That’s why LabVIEW has sometimes slipped in another function when you placed a From DDT or To DDT. Demo by examining Lab3DigitalInput.vi and Lab3DigitalOutput.vi.

11 Creating Arrays with Loops
A useful feature called auto- indexing on a loop lets you tell LabVIEW to create an array automatically when the loop runs. To enable or disable auto-indexing, right-click a tunnel on a loop’s border and select Enable Indexing or Disable Indexing. -Demo with For Loop that generates 50 random numbers; create indicator on the random number itself, and on a wire running from the random number to the border. Then create indicator on that tunnel. -Now we can understand difference between having indexing enabled or disabled (Week 5).

12 Removing Elements from an Array
To manually remove an element on the front panel, right-click the element and select Data Operations > Delete Element. To manually remove all elements, right-click the array’s index display and select Data Operations > Empty Array. -Demo deleting an element and emptying the array.

13 Array Functions The Functions >> Programming >> Array palette provides many functions for working with arrays, including: Array Size Index Array Array Subset Build Array Initialize Array Delete From Array

14 Array Size The Array Size function takes an array as its input. For its output, it returns the number of elements in that array. The input array can be of any data type (numeric, Boolean, string). The output returned by the function is an integer. (Bishop, p. 297) -Demo by placing an array of numeric controls, entering six or eight numbers, and then displaying the array size on an indicator.

15 Index Array The Index Array function takes an array and a number (called index) as its inputs. For its output, it returns the element at the index position in that array. The input array can be of any data type (numeric, Boolean, string). The output returned by the function is of the same type. (Bishop, p. 302) Demo with previous example.

16 Array Subset The Array Subset function takes an array and two numbers (one called index and one called length) as its inputs. For its output, it returns a new array containing the portion of the original array starting at index and containing length elements. The input array can be of any data type (numeric, Boolean, string). The output returned by the function is an array of the same type. (Bishop, p. 301) -Demo -This is one way to create an array on the block diagram.

17 Build Array The Build Array function takes arrays and/or individual data values as its inputs. For its output, it returns an array containing all elements from the input arrays and values. The input arrays and data values must be of the same type as each other (numeric, Boolean, string). The output returned by the function is an array of that same type. (Bishop, p. 300) -Demo by generating a few random numbers and building them into an array.

18 Initialize Array The Initialize Array function takes an integer n and a data value as its inputs. For its output, it returns a newly created array containing n elements, each of which is equal to the specified data value. The input data value can be of any data type (numeric, Boolean, string). The output returned by the function is an array of that same type. (Bishop, p. 298) -Demo by initializing and then displaying an array with 15 elements. -This gives a way of creating arrays on the block diagram, instead of on the front panel.

19 Delete From Array The Delete From Array function takes an array and two numbers (one called index and one called length) as its inputs. For its output, it returns a new array equal to the original array but without the length elements starting at index. The input array value can be of any data type (numeric, Boolean, string). The output returned by the function is an array of that same type. -Demo.

20 Some Other Array Functions
Here are a few other useful array functions that are easy to understand: Sort 1D Array Search 1D Array Reverse1D Array

21 Two-Dimensional Array
Think of a two-dimensional array as a set of items arranged in a table. Example: a table of student grades on the assignments in a class: 90, 86, 93, … 77, 92, 68, … 82, 84, 82, … : : : In this example, each row represents a different student, and each column represents a different assignment. You can refer to any element in this table by its row number and column number. -Again, without arrays, this would require a lot of numeric controls.

22 Creating a Two-Dimensional Array
To expand a front-panel 1-D array to 2-D, right-click the array’s index display and select Add Dimension.

23 Higher-Dimensional Arrays
Three-dimensional and higher-dimensional arrays are also possible, but we’ll concentrate on one-dimensional and two-dimensional arrays. Example of a 3-D array: if students took the same class again semester after semester, you could stack up versions of the table shown on the previous slide. You can refer to any element in this 3-D array by its row number, column number, and layer number.


Download ppt "EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3."

Similar presentations


Ads by Google