Comm 502 Communication Theory Lab: Introduction To Matlab
Comm 502 Communication Theory Lab: Introduction To Matlab
Workspace
Command
Window
Command
History
Getting Started:
clear Clears
workspace
Getting Started:
Variables:
Syntax Description
X=6 Integer
Y=[1 2 3 4] Vector
M=‘hello’ String
R=Inf ∞
S=pi π
Complex Numbers:
Syntax Description
a^b
ab
exp(a) ea
log10(a) log10 a
log2(a) log2 a
log(a) ln a
sqrt(a)
Vectors:
Syntax Description Output
X=[1 3 5 7 9] X=[x1 x2 x3 x4 x5] X=[1 3 5 7 9]
Z=X | Y Z = X OR Y Z=1
If Statements:
Switch:
Syntax Example
Output
switch switch_expr X=[1 8 7 -4 6] Y=12
case case_expr
statement,...,statement switch X(3)
case case {5}
{case_expr1,case_expr2,case_expr3,...} Y=11
statement,...,statement case {3,7}
... Y=12
otherwise otherwise
statement,...,statement Y=13
end end
Loops:
Syntax Example Output
for index = start:increment:end X=ones(1,6) X=[1 2 4 8 16 32]
statements for n = 2:1:6
end X(n) = 2 * X(n - 1)
end
while expression X=10 Y =8
statements Y=0 X=2
end while X>=3
Y=Y+1
X=X-1
end
Plotting
Syntax Description
X=[x1 x2 x3 x4 x5…………xn] Define both vectors
Y=[y1 y2 y3 y4 y5…………yn] then plot
plot(X,Y)
X=-pi:0.01*pi:pi; Define one vector and
Y=sin(X); define the other as a
plot(X,Y) function of it
Type the
functionality
you are
searching for
Notes:
• Matlab is case sensetive which means that X is not
equivalent to x.