You are on page 1of 5

Directory manipulations

pwd
cd ..
mkdir lecture1
cd lecture1
Save your work
diary lec1.txt
diary on
ls
diary off
Ask for help
help
help control\control
F1
Variables Scalars
2*3
a=1
a=1.0
a=1.1
format long

a
format short
b=1e-3
a+b
a^3
a=pi/2
sin(a)
a=1
atan(a)
c=1+2j
c=1+2i
real(c)
imag(c)
abs(c)
angle(c)
Variables Vectors and Matrices
a=[1 2 3 4]
b=[1,2,3,4]
c=1:4
d=3:2:9
a(4)
a(2:4)
e=[1;2;3;4]
f=d
g=[1 2 3; 4 5 6; 7 8 9]
h=[e f]
j=[a; d]
k=j*h
m=g

m(4, 4)=1
m([1 3], :)
m(:, [2 3])
More About Matrices
eye(3)
ones(2, 3)
zeros(4,1)
m=magic(3)
h
size(h)
a
length(a)
det(m)
[mv, md]=eig(m)
[1 2 3].*[4 5 6]
help matlab\elmat
help matlab\matfun
Strings
first=hello, world
length(first)
first(1:5)

Plotting a curve
x=0:pi/24:2*pi
y1=sin(x)
y2=cos(x)
plot(x,y1,r)
hold on
plot(x,y2,b--)
legend(sin,cos)
xlabel(angle (radian))
ylabel(func value)
title(sin/cos in [0, 2pi])
grid on
axis([0 2*pi -1 1])
sin/cosin[0,2pi]
1
0.8
sin
cos

0.6

func value

0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0

3
angle(radian)

Plotting a discrete signal


k=0:19
x=0.9*ones(1,20)
y=x.^k
z=cos(k*pi/6)
val=y.*z
stem(k, val, 'filled')
xlabel('time')
ylabel('value')
legend('u(k)=cos(k*pi/6)*0.9^k')
axis([-1 19 -1 1])
grid on

1
u(k)=cos(k*pi/6)*0.9

0.8

0.6
0.4

value

0.2
0
-0.2
-0.4
-0.6
-0.8
-1

10
tim
e

12

14

16

18

You might also like