Matlab Tutorial On Vector and Matrix: DR - Anandan P
Matlab Tutorial On Vector and Matrix: DR - Anandan P
on
Vector and Matrix
Dr.Anandan P
Faculty - Department of ECE
VelTech Rangarajan Dr.Sagunthala R&D
Institute of Science and Technology, Avadi,
Chennai.
Understanding the MATLAB
Environment
2
The desktop has the following panels:
Current Folder
Command Window
Workspace
Editor window
3
Current Folder
• This panel allows you to
access the project
folders and files.
4
Command Window
• This is the main area
where commands can
be entered at the
command line. It is
indicated by the
command prompt (>>).
5
Workspace
• The workspace shows
all the variables created
and/or imported from
files.
6
Editor window
• Commands can be
entered here and
executed as a script.
They are saved with a
.m extension. To run
your script, type in the
name at the command
prompt, or press F5 or
the save and run button
at the top of the editor
7
License?
• How to check the
license Number ?
8
;
• If you end a statement
with a semicolon,
MATLAB performs the
computation, but
suppresses the display
of output in the
Command Window.
9
Comments
• MATLAB treats all the
information after the % on a
line as a comment.
• To comment a group of
lines, type %{ before the first
line and %} after the last line
you want to comment.
10
Help
• To know more
info of a
command.
11
Array, Vector & Matrix
• Array is a collection of several values of the
same type.
• A vector is a one-dimensional array of
numbers.
• A matrix is a two-dimensional array of
numbers.
12
Creating a Row Vector
• Row vectors are created
by enclosing the set of
elements in square
brackets, using space or
comma to delimit the
elements.
13
Creating a Column Vector
• Column vectors are created
by enclosing the set of
elements in square
brackets, using semicolon to
delimit the elements.
14
Referencing the Elements of a Vector
• You can reference one or
more of the elements of a
vector in several ways. The
ith component of a vector v
is referred as v(i).
15
• When you reference a
vector with a colon, such
as v(:), all the
components of the vector
are listed.
16
Referencing a range of Elements in a
Vector
• Create a row vector rv of 9
elements, then we will
reference the elements 3 to
7 by writing rv(3:7) and
create a new vector named
sub_rv.
17
Vector Operations
Addition and Subtraction
You can add or subtract two
vectors. Both the operand
vectors must be of same type
and have same number of
elements.
18
Scalar Multiplication of Vectors
• When you multiply a
vector by a number, this
is called the scalar
multiplication
19
Transpose of a Vector
The transpose operation
changes a column vector
into a row vector and vice
versa. The transpose
operation is represented by
a single quote (').
20
Appending Vectors
• MATLAB allows you to
append vectors
together to create
new vectors.
21
Vector Dot Product
• Dot product of two
vectors
a = (a1, a2, …, an) and
b = (b1, b2, …, bn)
is given by:
a.b = Σ(ai.bi)
22
Vectors with Uniformly Spaced
Elements
• To create a vector v with the first element f, last element
l, and the difference between elements is any real
number n, we write:
v = [f : n : l]
23
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.
24
• For example, let us create a 4-by-5 matrix a:
25
Referencing the Elements of a Matrix
• To reference an element in the mth row and nth column,
of a matrix mx, we write: mx(m, n);
26
• To reference all the elements in the mth column we type
A(:,m)
• Let us create a column vector v, from the elements of the
4th column of the matrix a:
27
• You can also select the elements in the mth through
nth columns, for this we write:
a(:,m:n)
28
• In the same way, you can create a sub-matrix taking
a sub-part of a matrix.
• For example, let us create a sub-matrix sa taking the
inner subpart of a:
3 4 5
4 5 6
29
Deleting a Row or a Column in a Matrix
• You can delete an entire row or column of a matrix by
assigning an empty set of square braces [] to that row or
column. Basically, [] denotes an empty array.
• For example, let us delete the fourth row of a:
30
• Next, let us delete the fifth column of a:
31
Thank You