Professional Documents
Culture Documents
ACES 410
MATLAB OVERVIEW
Spring 2010
Dr Petros Christou
p.christou@frederick.ac.cy
http://staff.fit.ac.cy/eng.cp/
MATLAB
MATLAB is a software package for numerical computation.
It offers a powerful programming language, excellent
graphics, and a wide range of expert knowledge.
MATLAB DESKTOP
Set
Current Workspace/ Prompt: Enter Commands
Tab Current Directory Here
Window
Command
Window
Command
History
Window
v =
2 4 5
k =
2
4
3
m1 =
1 2 3
4 5 6
7 8 9
>> m2=[1 2 3
4 5 6
7 8 9]
m2 =
1 2 3
4 5 6
7 8 9
>> v2=0.0:0.1:0.7
v2 =
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
>> a=[1 2 3; 4 5 6; 7 8 9]
a =
1 2 3
4 5 6
7 8 9
>> a(2:3,1)
ans =
4
7
>> u-v
ans =
9 7 5
>> color=sentence(5:8)
color =
red
>> v2
v2 =
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
>> v2=v2(1:5)
v2 =
0 0.1000 0.2000 0.3000 0.4000
>> plot(v1,v2)
• Use ezplot
>> ezplot sin(x)
• Example
function s = threesum(x,y,z)
% Add three variables and return the result
s=x+y+z;
>> f(4)
ans =
21
MATLAB OVERVIEW ACES 410 : SPRING 2010 22
• Flow controls
– if statements
– switch statements
– for loops
– while loops
– continue statements
– break statements
icount =