You are on page 1of 8

ECE 100 Fundamentals of LabVIEW Programming

ARRAYS AND MATRICES


Activity No. 5

I. INTENDED LEARNING OUTCOMES

At the end of this activity, the student shall be able to:


1. State the function and importance of arrays and matrices.
2. Create a one-dimensional array.
3. Create a multidimensional array.
4. Use data or values from the previous loops.

II. BACKGROUND INFORMATION

An array can either resemble a vector or a matrix. As does a vector and a matrix, an array groups
similar pieces of data. An array consists of two different components, the elements (pieces of data) and the
dimension (the size of the array). Arrays may contain numeric, Boolean, path, string, waveform, and cluster
data types. They may be used as an indicator (output) or a control (input). Arrays are advantageous to use
when you are dealing with similar pieces of data and/or repetitive computations, which means that they are
ideal for storing waveform data and data from loop iterations with each array element being the loop
iteration value. The elements in the array are ordered or assigned a certain index. Arrays begin indexing
the elements at zero, so the first element will have an index of zero instead of one. This is very important to
remember when accessing data from an array.

III. LEARNING ACTIVITIES

ACTIVITY 5.1: CREATING A ONE-DIMENSIONAL ARRAY

1. Depending on the type of array you want to create, different methods in creating the array must be taken.
In the Front Panel, right click anywhere in an empty space and choose Controls Palette All-Controls
Array & Cluster Array

Page 36
ECE 100 Fundamentals of LabVIEW Programming

2. The array you create will have a control on the top-left side that will allow you to navigate through the
array. The number in the control box will indicate the index of the
element shown in the leftmost cell.

3. Notice when you first put the array on the front panel that it is empty.
You can determine your array type by inserting either a control or
indicator inside the array. For example, for a numerical indicator array:
On the Block Diagram of Procedure 1, Controls Palette Num Inds
Num Ind Place inside Array.

4. To make an Array indicator: Right-click on the arrow pointing


outward the indicatorCreateIndicator.

Question: Based on visual observation, how do you compare an Array control to an Array indicator
on the Front Panel?

Question: Based on visual observation, how do you compare an Array control to an Array indicator
on the Block Diagram?

Page 37
ECE 100 Fundamentals of LabVIEW Programming

5. You can control the viewing size of your array by dragging one of the corners where there is a little blue
box in either the vertical or horizontal direction. Thus, you can either make your one dimensional array
represent a column vector or a row vector, which will be important when performing mathematical
operations as arrays follow the same mathematical rules as do vectors and matrices. You may also notice
that the size of the array increases or decreases in increments of the current cell size.

6. For a constant array, proceed as follows in the Block Diagram, Functions


Palette Programming Array Array Constant. This array will look
similar to the previous one as it will be empty and it will have an array control
on the left side.
Question: How does an Array constant differ from Array control and
Array Indicator?

7. To make an Array control or Array Indicator an Array constant, right click on the Array Icon; choose
ReplaceProgrammingArrayArray constant.

ACTIVITY 5.2: CREATING A MULTIDIMENSIONAL ARRAY

1. Creating a multi-dimensional array (in mathematical terms, a


matrix) follows the same procedures as for creating a one-
dimensional array: To add another dimension to the one-
dimensional array, Right-Click on the Array Control (upper left
corner) Add Dimension (another array control will appear
below the original and you may now drag the viewing window in
both directions vertically and horizontally). The top array control
will control the row index and the bottom array control w ill control
the column index.

Question: What is the function of the array


control located at the leftmost part of the
array?

Page 38
ECE 100 Fundamentals of LabVIEW Programming

ACTIVITY 5.3: OPERATIONS ON ARRAYS

1. On the Block Diagram window, go to Functions palette and choose ProgrammingArray and drag
the array constant on the Block Diagram.

2. On the Functions palette, navigate to ProgrammingNumeric and drag and drop the Numeric
constant inside the array constant shell. You can resize the array element by dragging on the horizontal
direction at some point in the corner of the array.

3. Create and initialize two 1D array constants, containing six numeric elements, on the block diagram
similar to the array constants shown below.

4. Create a 1D array of numeric indicators on the front panel. Change the numeric type to a 32-bit integer.
Right-click on the array and select RepresentationI32.

5. Create a For-loop on the block diagram and place an add function inside the For-loop.

6. Wire one of the array constants into the For-loop and connect it to the x terminal of the add function.

The Block diagram should look like as shown on the next page.

Page 39
ECE 100 Fundamentals of LabVIEW Programming

7. Wire the other array constant into the For-loop and connect it to the y terminal of the add function.

Question: Why do we need to change the data representation of an Array Indicator in the Front
Panel to I-32? What does I-32 imply?

8. Your final block diagram and front panel should be similar to those shown below.

Page 40
ECE 100 Fundamentals of LabVIEW Programming

Block Diagram

Front Panel

9. Go to the front panel and run the VI. Note that each element in the array of numeric indicators is
populated with the sum of the corresponding elements in the two array constants. Save your VI as
Act5_3_1.VI
Question: After running the program, what is the resulting output? How did the VI work?

Question: Why do you think the VI run even the iteration constant is not set?

10. Try creating a VI as shown below with the following block diagram: Save your VI as Act5_3_2.VI.

Page 41
ECE 100 Fundamentals of LabVIEW Programming

Question: After running the program above, how many elements is the resulting array? Why do you
think that the program executes that resulting array?

11. Try creating a VI as shown below with the following block diagram: Save your VI as Act5_3_3.VI.

Question: After running the program above, how many elements is the resulting array? How does
the program execute the resulting array?

Page 42
ECE 100 Fundamentals of LabVIEW Programming

IV. MACHINE PROBLEM

1. Create a VI that would perform arithmetic operations (add, subtract, multiply and divide), as well as
arrays. Design your front panel as if it will look like a scientific calculator for arrays and matrices. It would be
good if the user is informed whether an operation is invalid and why. Create separate VIs for arrays
(ArrayCalculator.vi) and matrices (MatrixCalculator.vi)

2. Two more commonly done operations on matrices, specifically on square matrices, are finding
determinants and finding the inverse. Using arrays create a VI that would evaluate the determinant of a 2D
square array as user input; call this VI as Determinants.vi. Create a separate VI which will evaluate the
inverse of a 2D square array of numeric data using co-factors and expansion by minors; call the VI as
InverseMatrix.vi. Check your results using matrices and matrix functions (Functions >> Mathematics >>
Linear Algebra)

V. ASSESSMENT TASKS

1. What is a nested For-loop? Can we create an array using a nested For-Loop?

2. How does addition, subtraction, multiplication and division of arrays in LabVIEW works? State
mathematically on how to perform operations in arrays.

3. What is the importance of array manipulation in the context of LabVIEW programming?

VI. CONCLUSION

VII. RUBRICS FOR LABORATORY PERFORMANCE

Page 43

You might also like