1
Introduction to Matlab
Dr Jaylina Rana
Week 13
CIVE1007Y ‐ Professional Communication
2
• What is Matlab?
• Why use Matlab?
• What is possible in Matlab? Graphic examples
• How Matlab works?
3
What is Matlab?
• Numerical computing environment & programming
language.
• Created by The MathWorks, MATLAB allows easy:
▫ Matrix manipulation,
▫ Plotting of functions and data,
▫ Implementation of algorithms,
▫ Creation of user interfaces, and
▫ Interfacing with programs in other languages.
4
Why use Matlab?
• Allows quick and easy coding in a very high‐level language.
• Rich data types: Complex number, Three dimensional
matrix, structure, cell array, etc
• Lots of users: economists, mathematicians, engineers, …
• High‐quality graphics and visualization facilities are
available.
• MATLAB M‐files are completely portable across a wide
range of platforms.
5
Workspace: consists of the variables you
create during a MATLAB session;
Current Directory browser: shows you where
you are.
Launch Pad: displays all the tools and applications
associated with MATLAB
6
What kind of graphics is possible in Matlab?
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-3 -2 -1 0 1 2 3
x = -2.9:0.2:2.9;
bar(x,exp(-x.*x));
7
What kind of graphics is possible in Matlab?
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Line plot:
x=0:0.05:5;y=sin(x.^2);plot(x,y);
8
What kind of graphics is possible in Matlab?
0.35
0.3
0.25
0.2
0.15
0.1
0.05
-0.05
-0.1
-0.15
0 0.5 1 1.5 2 2.5 3 3.5 4
Stem plot:
x = 0:0.1:4;, y = sin(x.^2).*exp(-x);
stem(x,y)
9
What kind of graphics is possible in Matlab?
10
-5
-10
30
25
20
20
15
10 10
5
0 0
Mesh plot: z=peaks(25); mesh(z);
10
What kind of graphics is possible in Matlab?
10
-5
-10
30
25
20
20
15
10 10
5
0 0
Surface plot:
z=peaks(25);, surf(z);, colormap(jet);
11
What kind of graphics is possible in Matlab?
25
20
15
10
5 10 15 20 25
Contour plot: z=peaks(25); contour(z,16);
12
What kind of graphics is possible in Matlab?