CL2014 - MATLAB Programming - Lec03
CL2014 - MATLAB Programming - Lec03
MATLAB Programming
Lecture: 03
Course Instructor
Engr Muhammad Umar Khan Niazi
Office: C1-21, Ext.: 218, Email: umar.niazi@nu.edu.pk
1
2 Matrices & Arrays
A vector is a special type of matrix, having only one row or one column.
Vectors are called lists or arrays in other programming languages.
MATLAB refers to scalars, vectors, and matrices generally as arrays.
We will also use the term array generally, with vector and matrix
referring to the one-dimensional (1D) and two-dimensional (2D) array
3 Matrices & Arrays
NOTE:
• Array is stored by a specific name.
• The arrays are written in square brackets [ ].
• Elements of a row are separated by space.
a = [1 2 3; 4 5 6]
Results In
a =
1 2 3
4 5 6
13 Matrix Operations in MATLAB
ans =
1 4
2 5
3 6
14 Matrix Operations in MATLAB
A matrix can be constructed from column vectors of the same length. Thus,
the statements
x = 0:30:180;
table = [x’ sin(x*pi/180)’]
result in
table =
0 0
30.0000 0.5000
60.0000 0.8660
90.0000 1.0000
120.0000 0.8660
150.0000 0.5000
180.0000 0.0000
15 Matrix Operations in MATLAB
A*B is valid if A's number of column equals B's number of rows A^2 is