Ezplot, Plot and FPlot
We have used different plotting command to
plot the curve in MATLAB.
We will go through these command and check
what are the differences between these.
ezplot Command
ezplot(fun) plots the expression fun(x) over the default
domain -2π < x < 2π, where fun(x) is an explicit
function of only x.
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')
Passing a Function Handle
fh = @(x,y) x.^2 + y.^3 - 2*y - 1;
ezplot(fh)
plot Command
Plot function also plots a 2-D line plot.
plot(X,Y) creates a 2-D line plot of the data in Y versus
the corresponding values in X.
plot(X,Y,LineSpec) sets the line style, marker symbol,
and color.
plot(X1,Y1,...,Xn,Yn) plots multiple X, Y pairs using the
same axes for all lines.
plot
plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn) sets the line
style, marker type, and color for each line. You can mix
X, Y, LineSpec triplets with X, Y pairs.
For example, plot(X1,Y1,X2,Y2,LineSpec2,X3,Y3).
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
fplot(f) plots the curve defined by the function y = f(x)
over the default interval [-5 5] for x.
fplot(f,xinterval) plots over the specified interval.
Specify the interval as a two-element vector of the
form [xmin xmax].
fplot(funx,funy) plots the curve defined by x = funx(t)
and y = funy(t) over the default interval [-5 5] for t.
fplot(funx,funy,tinterval) plots over the specified
interval. Specify the interval as a two-element vector of
the form [tmin tmax].
fplot(___,LineSpec) specifies the line style, marker
symbol, and line color. For example, '-r' plots a red
line. Use this option after any of the input argument
combinations in the previous syntaxes.
Examples
Plot sin(x) over the default x interval [-5 5].
fplot(@(x) sin(x))
Plot Parametric Curve
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