Plotting Techniques in MATLAB
Plotting Techniques in MATLAB
ezplot(fun)
ezplot(fun,[xmin,xmax])
ezplot(funx,funy)
ezplot
For example
Passing the Function as a Character Vector or String
ezplot('x^2')
Ezplot('x^2-y^4')
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
Y = magic(4)
plot(Y)
Specify Line Style
x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
figure
plot(x,y1,x,y2,'--',x,y3,':')
Specify Line Style, Color, and Marker
x = linspace(0,10);
y = sin(x);
plot(x,y,'-o','MarkerIndices',1:5:length(y))
Line Style
Line Style Description
- Solid line
-- Dashed line
: Dotted line
-. Dash-dot line
Marker
Marker Description
'o' Circle
'+' Plus sign
'*' Asterisk
'.' Point
'x' Cross
'_' Horizontal line
'|' Vertical line
's' Square
'd' Diamond
'^' Upward-pointing triangle
'v' Downward-pointing triangle
'>' Right-pointing triangle
'<' Left-pointing triangle
'p' Pentagram
'h' Hexagram
Color
Color Description
y Yellow
m magenta
c cyan
r red
g green
b blue
w white
fplot Command
Plot expression or function
xt = @(t) cos(3*t);
yt = @(t) sin(2*t);
fplot(xt,yt)
Specify Plotting Interval and Plot
Piecewise Functions
fplot(@(x) sin(x+pi/5),'Linewidth',2);
hold on
fplot(@(x) sin(x-pi/5),'--or');
fplot(@(x) sin(x),'-.*c')
hold off
Plot Multiple Lines in Same Axes
fplot(@(x) sin(x))
hold on
fplot(@(x) cos(x))
hold off