Matlab Graphics: Mohamed Hussein
Matlab Graphics: Mohamed Hussein
by
Mohamed Hussein
compliments to
Prof. Michael Negnevitsky
Univerity of Tasmania
Lecture 2
Matlab Graphics
Creating
Simple Plots
Manipulating Plots
>> z = cos(x);
>> plot(x,y,x,z)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
>> plot(x,y,x,y,'+')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
Plots a sine twice, once with lines connecting the data points,
the second with the data points marked with the symbol +. 10
>> plot(y,z)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
>> grid
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
3
4
independent variable X
dependent variables
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
3
4
independent variable X
dependent variables
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
3
4
independent variable X
Colour
Symbol
yellow
point
magenta
circle
cyan
x-mark
red
plus
green
star
blue
solid line
white
dotted line
black
-.
dash-dot line
--
dashed line
Line style
17
>> x = linspace(0,2*pi,30);
>> y = sin(x);
>> z = cos(x);
>> plot(x,y,'b:',x,z,'r--',x,y,'ko',x,z,'m+')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
18
Manipulating Plots
We add lines to existing plots using the
command hold. Matlab does not remove
the existing curves when new plot
commands are issued. It adds new curves
to the current axes.
Setting hold off releases the current figure
window for new plots.
19
>> x = linspace(0,2*pi,30);
>> y = sin(x);
>> plot(x,y)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
>> hold on
>> plot(x,z,'m')
>> hold off
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0