Unit 9 PowerPoint Slides

advertisement
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
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
Dimension of an Array


Every array has a dimension.
We’ll deal primarily with 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,
:
Floyd, Digital Fundamentals, 10th ed
(Bishop, p. 289)
Creating an Array of Controls or
Indicators

1.
2.
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.
(Bishop, p. 290)
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
Array Wires on Block Diagram

On the block diagram, a wire carrying an
array of data values appears thicker than a
wire carrying a single data value.
(Bishop, p. 292)
Floyd, Digital Fundamentals, 10th ed
Arrays & the DAQ Assistant


When you use the DAQ Assistant to
perform a digital input task, the DAQ
Assistant produces an array of Boolean
values.
And when you use the DAQ Assistant to
perform a digital output task, you must
provide the DAQ Assistant with an array of
Boolean values.
Floyd, Digital Fundamentals, 10th ed
Creating Arrays with Loops


A feature called auto-indexing on For
Loops and While Loops lets you tell
LabVIEW to create arrays automatically
when the loops run.
To enable or disable auto-indexing, rightclick a tunnel on a loop’s border and select
Enable Indexing or Disable Indexing.
(Bishop, p. 293)
Floyd, Digital Fundamentals, 10th ed
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
Floyd, Digital Fundamentals, 10 ed
Array.

th
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
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
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.
Floyd, Digital Fundamentals, 10th ed
(Bishop, p. 301)
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)
Floyd, Digital Fundamentals, 10th ed
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)
Floyd, Digital Fundamentals, 10th ed
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.
Floyd, Digital Fundamentals, 10th ed
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 all of the
assignments in a class:
90, 86, 93, …
77, 92, 68, …
82, 84, 82, …
95, 89, 94, …
60, 80, 75, …
: : :
Floyd, Digital Fundamentals, 10th ed
Higher-Dimensional Arrays

Three-dimensional and higher-dimensional
arrays are also possible, but we’ll
concentrate on one-dimensional and twodimensional arrays.
Floyd, Digital Fundamentals, 10th ed
Download