2. After the Advance


MATLAB function fplot() is used to generate symbolic plots with respect to expressions or functions. The default range of interval for the graph generated out of the fplot() function is [-5,5].


The below code is designed to generate a plot for the function tan(2x) using the fplot() method.


Output: The plot is generated for the function tan(2*var) with respect to the values of var ranging from -5 to 5.

Matlab fplot() - 1


Based on the input argument given in the function call, there is the various syntax which can be used to implement the fplot() method as described below:

SyntaxAttribute Description
fplot(f)f is the function or expression for which the plot is to be generated
fplot(f,xinterval)/fplot(f,[xminxmax])Xmin- initial limit of the interval from which the plotting f(x) should be initiatedXmax-  final limit of the interval at which the plotting f(x) should be completed
fplot(pt,qt)ptand qt are two different function of common variable t i.e. pt=p(t) and qt=q(t)
fplot(pt,qt,tinterval)/fplot(pt,qt,[tmintmax])tmin- initial limit of the interval from which the plotting p(t) and q(t) should be initiatedtmax-  final limit of the interval at which the plotting p(t) and q(t) should be completed.
fplot(___,LineSpec)Linespec is used to customize the plot presentation by customizing set the line color, marker symbol, and line styleetc.
fplot(___,Name,Value)Used to set property ‘Name’ with the value ‘Value’ for the plot
fplot(ax,___)Used to create plot with the newly defined axes ax, instead of default ones
p = fplot(___)The output from the fplot() function call is stored in parameterized line object

Methods of Matlab fplot()

Let’s understand the application of various syntax for implementing the method fplot() by means of examples.

Method 1 – Using the syntax fplot(x)

In the below example there is only one input argument i.e. the expression function defined with the depending variable x. Here, the value range for the variable x is set to default values i.e. [-5,5].

syms func(x)
func(x) = sin(x);



Method 2 – Using the syntax fplot(f,finterval)

The below code is written to generate a pot for the given expression func(x) within the specified time interval i.e. finterval.


syms func(x)
func(x) = sin(x);

Output: The resultant plot is generated for the expression of sin(x) for the defined range of values -2 to 2.


Method 3 – Using the syntax fplot(pt,qt)

The below MATLAB code is designed to generate plots for two functions pt, qt with the common depending variable t with the single call of the method fplot().


 The value range for the depending variable t is the default value set i.e. [-5,5].

pt = @(t) tan(2*t);
qt = @(t) cot(3*t);



Method 4 – Using the syntax fplot(pt,qt,tinterval)


pt = @(t) tan(2*t);
qt = @(t) cot(3*t);

Output: The resultant graph generated from the above code, contains the plots for the expressions tan(2t) and cot(3t) for the depending variable t within the specified time range of [-1,1].


Method 4 – Using the syntax p=fplot(——)

The below code is written to demonstrate the behavior of the function fplot() with a parametric object.

First phase


 The plot is generated using function call fplot() and is assigned to the parametric variable ‘p’.

syms var
p = fplot(cos(var))


Matlab fplot() - 6

Second Phase


The presentation of the plot is customized by editing the attribute values accessing through the parametric object ‘p’.

p.LineStyle = '--';
p.Color = 'r';
p.Marker = 'x';
p.MarkerEdgeColor = 'b';


Matlab fplot() - 7


The below code is written to generate the plot for the given function expression with editing representation of the graph by including title, x,y labels and tick values.


syms var
fplot(cos(var),[-2*pi 2*pi])
grid on
title('sin(var) from -2\pi to 2\pi')
nx = gca;
S = sym(nx.XLim(1):pi/2:nx.XLim(2));
nx.XTick = double(S);
nx.XTickLabel = arrayfun(@texlabel,S,'UniformOutput',false);


tick values

The plot is generated for the expression sin(var) for the range of values of var, -2\pi to 2\pi.The title of the graph as ‘sin(var) from -2\pi to 2\pi’, xlabel as ‘var’ and ylable as ‘f’ is set.

Different Attributes Supported by fplot()

There are various attributes that are supported by fplot() to edit the display of the plot. The major attributes are described in the below table:

LineSpecUsed to customize the display of the plot lines, markers, etc.
ColorUsed to decide the color of the line
LineStyleUsed to decide the style of the line
MarkerDecides the symbol be used as a marker
MarkerEdgeColorUsed to decide the outline color of the marker
MarkerFaceColorUsed to set the color to be filled in the marker
MarkerSizeDecides the size of the marker
MeshDensityTo set the number of the evaluation point

Examples to Implement Matlab fplot()

Below are the examples mentioned:

Example 1:

The below code snippet is designed to plot the functions ‘pt’ and ‘qt’ and regulating the attribute Linewidth.


pt = @(t) tan(2*t);
qt = @(t) cot(3*t);


functions pt and qt

The resultant plot generated from the method fplot() for the functions pt and qt is presented with a modified line width value 2.

Example 2:

The smoothness, accuracy, and speed of the drawing of the plot are controlled by the option MeshDensity which is the count for evaluation points.


syms x
Funcstep = rectangularPulse(2.1, 2.15, x);
title(' MeshDensity (Default value) = 23')
title(' MeshDensity (Increased value)= 50')


plotting multiple functions

The method fplot() also supports plotting multiple functions in one single frame by splitting the layout into the same number of cells.

Example 3:


syms var
fplot([sin(var) cos(var)])
title('Multiple plots on single layout')
hold on
title('Multiple plots with  Command hold on')
hold off


Matlab fplot() - 11

Additional Note

Below are the additional note for Matlab fplot():

1. Re-evaluation on Zoom: The plot generated from the fplot can be reevaluated by using the zooming feature. It helps the user to reveal the hidden details in the plot.


syms var
axis([-2 2 -0.02 0.02]);
for i=1:5


Re-evaluation on Zoom

2. In casefplot(f) syntax or any of its variation is used, then returned object is of type FunctionLine objects whereas in case of fplot(funx,funy) syntax,the object return type is ParameterizedFunctionLine.

Thus the function fplot() in MATLAB supports advanced plotting features for any kind of function or expressions along with providing a wide range of customization flexibility.

Leave a Reply

Your email address will not be published. Required fields are marked *