LAB 4 Matlab
LAB 4 Matlab
LAB # 04
1
Signals & Systems Lab # 1
Objective:
Creating, concatenating, and expanding matrices in MATLAB Also trace the graphical plot of
the matrixes in MATLAB.
Discussion:
Array Definition:
An array is the most fundamental data type in MATLAB. In MATLAB, as in many traditional languages,
arrays are a collection of several values of the same type. ... A matrix is an array with two dimensions.
Most arrays have the same data type; however, a cell array is an array with varying data types.
A=[1 2 3 4]
Matrix Definition
A matrix is a rectangular array of numbers arranged in rows and columns. The array of numbers below is
an example of a matrix. A matrix is a two-dimensional array of numbers. In MATLAB, you create a matrix
by entering elements in each row as comma or space delimited numbers and using semicolons to mark
the end of each row.
21 62 93
a = 44 95 13
77 38
33
The number of rows and columns that a matrix has is called its dimension or its order.
To transpose a matrix, use a single quote ('):
2
Signals & Systems Lab # 1
21 44 77
a’ = 62 95 38
93 13
33
To perform element-wise multiplication rather than matrix multiplication, use the .* operator:
a.*a
The matrix operators for multiplication, division, and power each have a corresponding array operator that
operates element-wise. For example, raise each element of a to the third power:
123 a =
456
78
10
a.^3
1 8 27
64 125 216
343 512 1000
Now create a matrix with the same numbers, but arrange them in two rows. This matrix has two rows
and two columns
3
Signals & Systems Lab # 1
Concatenating Matrices
Concatenation is the process of joining arrays to make larger ones. In fact, you made your first array
by concatenating its individual elements. The pair of square brackets [] is the concatenation operator.
A = [a,a]
You can also use square brackets to join existing matrices together. This way of creating a matrix is
called concatenation. For example, concatenate two row vectors to make an even longer row vector.
A = ones(1,4);
B = zeros(1,4);
C = [A B]
C = 1×8
1 1 1 1 0 0 0 0
1 1 1 1
0 0 0 0
To concatenate two matrices, they must have compatible sizes. In other words, when you concatenate
matrices horizontally, they must have the same number of rows. When you concatenate them vertically,
they must have the same number of columns. For example, horizontally concatenate two matrices that
both have two rows.
A = ones(2,3)
A = 2×3
1 1 1
1 1 1
Specialized Matrix Functions
MATLAB has many functions that help create matrices with certain values or a particular structure. For
example, the zeros and ones functions create matrices of all zeros or all ones. The first and second
arguments of these functions are the number of rows and number of columns of the matrix, respectively.
A = zeros(3,2)
A = 3×2
0 0
0 0
0 0
4
Signals & Systems Lab # 1
B = ones(2,4)
B = 2×4
1 1 1 1
1 1 1 1
Expanding a Matrix
You can add one or more elements to a matrix by placing them outside of the existing row and column
index boundaries. MATLAB automatically pads the matrix with zeros to keep it rectangular. For example,
create a 2-by-3 matrix and add an additional row and column to it by inserting an element in the (3,4)
position.
A = [10 20 30; 60 70 80]
A = 2×3
10 20 30
60 70 80
A(3,4) = 1
A = 3×4
10 20 30 0
60 70 80 0
0 0 0 1
You can also expand the size by inserting a new matrix outside of the existing index ranges.
A(4:5,5:6) = [2 3; 4 5]
A = 5×6
10 20 30 0 0 0
60 70 80 0 0 0
0 0 0 1 0 0
0 0 0 0 2 3
0 0 0 0 4 5
5
Signals & Systems Lab # 1
TASKS:
1. Make a table of first ten positive integer multiples of 1 to 5. Display
them in a matrix form in a way that each column of matrix is the
first ten positive integer multiples of 1 to 5. The first column is for
integer multiples of 1 and vice versa.
6
Signals & Systems Lab # 1
7
Signals & Systems Lab # 1
3. Assume the array array1 is defined as shown, and determine the contents of the following
sub-arrays.
1.1 0.0 2.1 -3.5 6.0
array1= 0.0 1.1 -6.6 2.8 3.4
2.1 0.1 0.3 -0.4 1.3
-1.4 5.1 0.0 1.1 0.0
a. array1 (3,:)
b. array1 (:,3)
8
Signals & Systems Lab # 1
4.
a. Create a simple vector with 9 elements called a = [1 2 3 4 6 4 3 4 5]
b. Create vector b Adding 2 in vector a.
c. Plot the result of our vector addition with grid lines.
d. Make other graph types as well, with axis labels
e. Make graph using symbols in plots.
9
Signals & Systems Lab # 1
Levels
PLO
no Criteria Beginning (1) Developing (2) Accomplished (3) Exemplary (4)
With instructor/ supervisor’s With instructor/ supervisor’s Student is able to apply all
Apply Procedural Student is unable to apply guidance, student is able to guidance, student is able to procedural knowledge to
Knowledge to described procedure to perform apply some of the described apply all described independently perform
1
perform an activity despite instructor/ procedure to partially perform procedure to fully perform activity without instructor/
activity supervisor’s guidance. activity. activity. supervisor’s guidance.
Student is able to
Design With instructor/ supervisor’s
Student is unable to design With instructor/ supervisor’s independently design
systems systems, components and/or guidance, student is able to systems, components and/or
guidance, student is able to
, components fully design systems, processes to meet
3 processes to meet specifications partially design systems,
and/or processes components and/or
despite instructor/ supervisor’s components and/or processes to specifications without
to meet processes to meet
guidance. meet specifications. instructor/ supervisor’s
specifications specifications. guidance.
Data Analysis Student is unable to analyze/ Student is able to
With instructor/ supervisor’s With instructor/ supervisor’s
and interpret obtained results independently
guidance, student is able to guidance, student is able to
4 interpretation of despite instructor/ supervisor’s analyze/interpret obtained
partially analyze/interpret fully analyze/interpret
obtained results guidance. results without instructor/
obtained results. obtained results.
supervisor’s guidance.
Operational Student has shown little to no
With instructor/ supervisor’s With instructor/ supervisor’s Student can handle/use all
Skills for ability to handle/use
guidance, student can guidance, student can equipment/software and
Hardware/Softw equipment/software and
5 handle/use some of the handle/use all involved components without
are equipment involved components despite
equipment/ software and equipment/software and instructor/ supervisor’s
and involved instructor/ supervisor’s
involved components. involved components. guidance.
components guidance.
10
Signals & Systems Lab # 1
Group No.
C P Domain
N L L + Criteria Awarded Score (out of 4 for each cell)
o. O O Taxonomy
1 5 5 P3 Operational Skills for Hardware/Software equipment and
involved components
2 6 10 A3 Effectively reported the activity performed in lab
- - - -
Total
-
11