EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

Matlab fplot()

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » Matlab Tutorial » Matlab fplot()

Matlab fplot()

Introduction to Matlab fplot()

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].

Example

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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

symsvar
fplot(tan(2*var))

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

Syntax

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:

Syntax Attribute 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 initiated

Xmax-  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 initiated

tmax-  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.

Popular Course in this category
Sale
MATLAB Training (3 Courses, 1 Project)3 Online Courses | 1 Hands-on Project | 8+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (9,200 ratings)
Course Price

View Course

Related Courses
R Programming Training (13 Courses, 20+ Projects)All in One Data Science Bundle (360+ Courses, 50+ projects)

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);
fplot(func)

Output:

fplot(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.

Code:

syms func(x)
func(x) = sin(x);
fplot(func,[-2,2])

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

fplot(f,finterval)

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().

Code: 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);
fplot(pt,qt)

Output:

fplot(pt,qt)

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

Code:

pt = @(t) tan(2*t);
qt = @(t) cot(3*t);
fplot(pt,qt,[-1,1])

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].

5(pt,qt,tinterval)

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

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

syms var
p = fplot(cos(var))

Output:

Matlab fplot() - 6

Second Phase

Code: 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';

Output:

Matlab fplot() - 7

Example

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.

Code:

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

Output:

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:

Attribute Description
LineSpec Used to customize the display of the plot lines, markers, etc.
Color Used to decide the color of the line
LineStyle Used to decide the style of the line
Marker Decides the symbol be used as a marker
MarkerEdgeColor Used to decide the outline color of the marker
MarkerFaceColor Used to set the color to be filled in the marker
MarkerSize Decides the size of the marker
MeshDensity To 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.

Code:

pt = @(t) tan(2*t);
qt = @(t) cot(3*t);
fplot(pt,qt,'-.*c','Linewidth',2)

Output:

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.

Code:

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

Output:

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

Code:

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

Output:

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.

Code:

syms var
fplot(var^2*cos(1/var));
axis([-2 2 -0.02 0.02]);
for i=1:5
zoom(1.6)
pause(0.6)
end

Output:

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.

Recommended Articles

This is a guide to Matlab fplot(). Here we discuss the methods to know, with examples to implement with additional notes in detail. You can also go through our other related articles to learn more –

  1. Matlab colorbar Label
  2. Boxplot in Matlab
  3. Plot Vector Matlab
  4. Quiver Matlab 

MATLAB Training (3 Courses, 1 Project)

3 Online Courses

1 Hands-on Project

8+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Matlab Tutorial
  • Advanced
    • MATLAB Class
    • Arrays in MATLAB
    • Matlab find value in array
    • Power Spectral Density MATLAB
    • Matlab Textscan
    • String Array in MATLAB
    • MATLAB Random Numbers
    • Matlab Dot
    • MATLAB 2D Array
    • MATLAB? zero padding
    • MATLAB sort matrix
    • MATLAB Plot Function
    • 2D Plots in MATLAB
    • 3D Plots in MATLAB
    • MATLAB Fread
    • Spectrogram MATLAB
    • MATLAB Average
    • MATLAB exponent
    • MATLAB not enough input arguments
    • MATLAB comment
    • MATLAB zpk
    • Scatter Plots in MATLAB
    • MATLAB 3d scatter plot
    • Bar Graph in MATLAB
    • Bar Plot MATLAB
    • Log Plot MATLAB
    • Polar Plot in MATLAB
    • Surface Plot in MATLAB
    • MATLAB Plot Circle
    • Boxplot in MATLAB
    • MATLAB Plot Multiple Lines
    • Linspace MATLAB
    • Histogram in MATLAB
    • Plot Vector MATLAB
    • MATLAB Legend
    • MATLAB Plot Legend
    • MATLAB ezplots
    • Column Vector MATLAB
    • MATLAB Plot Marker
    • MATLAB LineWidth
    • MATLAB Line Style
    • Contour plot in MATLAB
    • MATLAB Sine Wave
    • Reshape in MATLAB
    • Natural Log in MATLAB
    • Random Number Generator in MATLAB
    • Complex Numbers in MATLAB
    • MATLAB Figure
    • Heatmap in MATLAB
    • MATLAB Technical Computing
    • Colors in MATLAB
    • Colormap in MATLAB
    • MATLAB Plot Colors
    • MATLAB fplot()
    • MATLAB Stacked Bar
    • MATLAB sphere()
    • MATLAB cylinder()
    • MATLAB mesh()
    • Pie Chart in MATLAB
    • MATLAB Gradient
    • Grid on MATLAB
    • Repmat in MATLAB
    • dlmread in MATLAB
    • Meshgrid in MATLAB
    • MATLAB Struct
    • MATLAB Cross Product
    • MATLAB colorbar Label
    • MATLAB Save Variable
    • MATLAB Saveas
    • MATLAB Cell Array
    • Polynomial in MATLAB
    • ismember MATLAB
    • Heaviside MATLAB
    • MATLAB rref
    • MATLAB polyfit()
    • MATLAB xlim
    • MATLAB Variance
    • Optimset MATLAB
    • Quiver MATLAB
    • Newton Raphson MATLAB
    • Mat2cell MATLAB
    • Magnitude MATLAB
    • format long MATLAB
    • Dot Product MATLAB
    • Jacobian MATLAB
    • What is Matlab?
    • Convolution MATLAB
    • Moving Average MATLAB
    • Fourier Series MATLAB
    • Gaussian Fit MATLAB
    • Bisection Method MATLAB
    • Laplace Transform MATLAB
    • Fourier Transform MATLAB
    • Signal Processing MATLAB
    • MATLAB Forms
    • Complex Conjugate MATLAB
    • MATLAB Write to File
    • uigetfile MATLAB
    • MATLAB Toolbox
    • MATLAB Errorbar
    • MATLAB Index Exceeds Matrix Dimensions
    • Nyquist MATLAB
    • Impulse Response MATLAB
    • xlsread MATLAB
    • MATLAB xlswrite
    • Matplotlib Scatter
    • MATLAB Import Data
    • MATLAB Export Data
    • MATLAB Read CSV
  • Basic
    • MATLAB Area Under Curve
    • MATLAB not equal
    • MATLAB max
    • MATLAB exist
    • MATLAB Table
    • MATLAB regression
    • MATLAB Lists
    • MATLAB quantile
    • MATLAB Round
    • MATLAB readtable
    • MATLAB disp
    • MATLAB Standard Deviation
    • MATLAB quadprog
    • MATLAB Transpose
    • Introduction to MATLAB
    • Advantages of MATLAB
    • MATLAB Features
    • Taylor Series MATLAB
    • MATLAB Z Transform
    • fsolve in MATLAB
    • Is MATLAB Free
    • MATLAB QR
    • Career in MATLAB
    • Uses Of MATLAB
    • Is MATLAB Free
    • How to Install MATLAB
    • How to Use MATLAB?
    • MATLAB Version
    • MATLAB Compiler
    • MATLAB Commands
    • MATLAB Block Comment
    • MATLAB? sprintf
    • MATLAB fprintf
    • Data Types in MATLAB
    • MATLAB Integral
    • MATLAB Double Integral
    • MATLAB boolean
    • MATLAB vpa
    • MATLAB Object
    • MATLAB Annotation
    • MATLAB Variables
    • MATLAB Global Variables
    • MATLAB Operators
    • MATLAB Logical Operators
    • MATLAB nan
    • MATLAB Patch
    • MATLAB AND Operator
    • MATLAB OR Operator
    • Vectors in MATLAB
    • What is Simulink in MATLAB
    • MATLAB Interpolation
    • MATLAB Imread
    • fscanf MATLAB
    • Euler Method MATLAB
    • Root Locus MATLAB
    • MATLAB return
    • Bode Plot MATLAB
    • Nargin MATLAB
    • MATLAB Matrix Inverse
    • MATLAB String to Number
    • MATLAB string
    • MATLAB ColorBar
    • MATLAB Surfc
    • MATLAB Concatenate
    • NUMEL MATLAB
    • MATLAB? File Extension
    • MATLAB File
    • MATLAB Smooth
    • MATLAB ones
    • Exponential in MATLAB
    • MATLAB ksdensity
    • MATLAB log
    • MATLAB Append
    • MATLAB hold on
    • MATLAB Magnitude of Vector
    • Heatmap in MATLAB
    • MATLAB xticks
    • MATLAB randn
  • Control Statements
    • IF-Else Statement in MATLAB
    • If Statement in MATLAB
    • Loops in MATLAB
    • For Loop in MATLAB
    • While Loop in MATLAB
    • do while loop in MATLAB
    • Nested Loop in MATLAB
    • Switch Statement in MATLAB
    • Break in MATLAB
  • Functions
    • MATLAB Functions
    • MATLAB user defined function
    • Calling Functions in MATLAB
    • Transfer Functions in MATLAB
    • Anonymous Functions in MATLAB
    • Inline Functions in MATLAB
    • Bessel Functions in MATLAB
    • Mean Function in MATLAB
    • Find Function MATLAB
    • Filter Function in MATLAB
    • IIR Filter MATLAB
    • Piecewise Function in MATLAB
    • Sum Function in MATLAB
    • Simulink MATLAB Function
    • MATLAB Create Function
    • MATLAB Inverse Function
    • MATLAB Count
    • Step Function MATLAB
    • MATLAB limit
    • fminsearch in MATLAB
    • Covariance in MATLAB
    • Summation in MATLAB
    • Linear Fit MATLAB
    • MATLAB?linear regression
    • MATLAB Derivative
    • MATLAB Derivative of Function
    • MATLAB Comet()
    • Fzero MATLAB
    • xlabel MATLAB
    • Matplotlib Legend
    • Matplotlib Subplots
    • Plot graph MATLAB
    • MATLAB Format
    • MATLAB plot title
    • Multiple Plots in MATLAB
    • MATLAB Indexing
    • Ceil MATLAB
    • Curve Fitting MATLAB
    • MATLAB trapz()
    • MATLAB Normalize
    • MATLAB diff
    • MATLAB sym()
    • MATLAB Syms
    • Absolute Value MATLAB
    • MATLAB Exponential
    • Kalman Filter MATLAB
    • Low Pass Filter MATLAB
    • Bandpass Filter MATLAB
    • MATLAB Unique
    • Trapezoidal Rule MATLAB
    • MATLAB Root Finding
    • MATLAB stem()
    • MATLAB loglog()
    • MATLAB Autocorrelation
    • MATLAB Sort
    • Simplify MATLAB
    • Cumsum MATLAB
    • Eval Function MATLAB
    • Polyval MATLAB
    • MATLAB Colon
    • MATLAB Eigenvalues
    • MATLAB fit
    • Delta Function MATLAB
    • MATLAB Remainder
    • Differentiation in MATLAB
    • Permute MATLAB
    • isempty MATLAB
    • MATLAB text()
    • MATLAB Display Text
    • Varargin in MATLAB
    • MATLAB gca
    • MATLAB fill()
    • MATLAB pcolor()
    • MATLAB min
    • MATLAB xcorr
    • MATLAB? color codes
    • Semilogy MATLAB
    • MATLAB? eye
    • feval MATLAB
    • num2str in MATLAB
    • MATLAB Images
    • MATLAB Image? Segmentation
    • Imagesc MATLAB
    • MATLAB Image Processing
    • MATLAB Image Resize
    • MATLAB Flag
    • MATLAB fopen
    • Strcmp MATLAB
    • MATLAB fwrite
    • MATLAB fft()
    • MATLAB zeros()
    • MATLAB textread
    • Arctan MATLAB
    • MATLAB Scripts
    • Butterworth filter MATLAB
    • MATLAB Findpeaks
    • MATLAB find Index
    • MATLAB Cell
    • MATLAB Unit Step Function
    • MATLAB Backslash
    • MATLAB Mod
    • Size Function in MATLAB
    • Secant MATLAB
  • Matrix
    • Matrix in MATLAB
    • 3D Matrix in MATLAB
    • Transpose Matrix MATLAB
    • Sparse Matrix in MATLAB
    • Matrix Multiplication in MATLAB
    • Identity Matrix in MATLAB
    • MATLAB?writematrix
  • Programs
    • Square Root in MATLAB
    • Square Wave MATLAB
    • Squeeze MATLAB
    • Factorial in MATLAB
    • Cell to String MATLAB
  • Interview Questions
    • MATLAB Interview Questions

Related Courses

MATLAB Certification Course

R Programming Course

All in One Data Science Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Independence Day Offer - MATLAB Training (3 Courses, 1 Project) Learn More