بسم الله الرحمن الرحيم

‫بسم هللا الرحمن الرحيم‬
King Abdulaziz University
College of Engineering
Dept of Electrical & Computer Engineering
Structured Computer Programming EE 201
Introduction to MATLAB 7
for Engineers
Chapter 1
Lecture 3
Basic Syntax and Command
 a11

a21

A 


ak1
m columns
a12   a1m 
 
a22

  K rows



       akm 
A’ Inverse Matrix A
A(n,d) Elements in row n & column d
RESHAPE Change size
RESHAPE(A,s,z) condition s*z = k*m
flipud(A)
FLIPUD Flip matrix in up/down direction.
FLIPUD(X) returns X with columns preserved and rows flipped
in the up/down direction. For example,
X= 1 4
2 5
3 6
becomes
3 6
2 5
1 4
fliplr(A) FLIPLR Flip matrix in left/right direction.
FLIPLR(X) returns X with row preserved and columns flipped in the left/right direction.
X= 1 2 3
4 5 6
becomes 3 2 1
6 5 4
Exercise:
If x = [3 1 5 7 9 2 6]
Summarize the net result of the command.
a.
x(3)
b.
x(1:7)
c.
x(1:end)
d.
x(1:end-1)
e.
x(6:-2:1)
f.
x([1 6 2 1 1])
g.
sum(x)
Matrix & Array
If A = [ a11,a12; a21,a22] & B = [ b11,b12; b21,b22]
there is a difference between * and .*
* is Matrix multiply
A*B = [ a11* b11 + a11 *b21 , a12* b11 + a12 *b21 , a21* b21 + a21
*b22 , a22* b21 + a22 *b22]
But .* is Array multiply
A.*B = [ a11* b11 , a12 *b12 ; a21*b21 , a22*b22]
Do it by your self and note what is the difference between ( ./ and / ) , ( .\
and \ )
Extra commands
floor Round towards minus infinity.
floor(X) rounds the elements of X to the nearest integers towards minus
infinity.
ceil Round towards plus infinity.
ceil(X) rounds the elements of X to the nearest integers towards infinity.
fix Round towards zero.
fix(X) rounds the elements of X to the nearest integers towards zero.
round Round towards nearest integer.
round(X) rounds the elements of X to the nearest integers.
Getting Help
􀂄Throughout each chapter margin notes identify where key
terms are introduced.
􀂄Each chapter contains tables summarizing the MATLAB
commands introduced in that chapter.
􀂄At the end of each chapter is a summary guide to the commands
covered in that chapter.
􀂄Appendix A contains tables of MATLAB commands, grouped
by category, with the appropriate page references.
􀂄There are three indexes. The first lists MATLAB commands and
symbols, the second lists Simulinkblocks, and the third lists topics.
King Abdulaziz University
EE 201
Eng. Ghassan R. Alnwaimi
The Help Navigator contains four tabs:

Contents: a contents listing tab,

Index: a global index tab,

Search: a search tab having a find function and full text search features,

Demos: a book marking tab to start built-in demonstrations.
The MATLAB Help Browser.
Help Functions

help funcname: Displays in the Command window a description of
the specified function funcname.

lookfor topic: Displays in the Command window a brief description
for all functions whose description includes the specified key word
topic.

doc funcname: Opens the Help Browser to the reference page for the
specified function funcname, providing a description, additional
remarks, and examples.
Relational operators
Relational
operator
<
<=
>
>=
==
~=
Meaning
Less than.
Less than or equal to.
Greater than.
Greater than or equal to.
Equal to.
Not equal to.
Examples of Relational Operators
>> x = [6,3,9]; y = [14,2,9];
>> z = (x < y)
z =1 0 0
>>z = ( x > y)
z =0 1 0
>>z = (x ~= y)
z =1 1 0
>>z = ( x == y)
z =0 0 1
>>z = (x > 8)
z =0 0 1
The find Function
find(x) computes an array containing the indices of the non zero
elements of the numeric array x. For example
>>x = [-2, 0, 4];
>>y = find(x)
y =1 3
The resulting array y = [1, 3]indicates that the first and third elements of
x are nonzero.

Note the difference between the result obtained by x(x<y) and the
result obtained by find(x<y).
>>x = [6,3,9,11];y = [14,2,9,13];
>>values = x(x<y)
values =6 11
>>how_many = length(values)
how_many =2
>>indices = find(x<y)
indices =1 4
Extra in Plotting
rectangular
Paper semi log
paper (logarithm on the y-axis) log-log paper