EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial MATLAB Plot Function
 

MATLAB Plot Function

Priya Pedamkar
Article byPriya Pedamkar

MATLAB Plot Function

Introduction to MATLAB Plot Function

MATLAB or Matrix Laboratory is a programming language that was developed by MathWorks. This powerful language finds its utility in technical computing. MATLAB provides us with a convenient environment that can be used to integrate tasks like manipulations on matrix, plotting data and functions, implementing algorithms, creating user interfaces, etc. MATLAB is also convenient as it gives the solutions in the form that its user can easily understand. It uses mathematical notations to display the solutions.

 

 

Where can MATLAB be used?

Below are a few areas where we can use MATLAB:

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

  • Computation
  • Development of Algorithms
  • Modeling
  • Simulation
  • Prototyping
  • Analysis and Visualization of data
  • Scientific graphs
  • Engineering graphics
  • Developing applications

MATLAB comprises a number of techniques to perform the above-mentioned uses. The objective of this article is to have a thorough understanding of plot functions in MATLAB. As the name suggests, the purpose of the plot function is to plot the graph of a function in MATLAB. We use a plot function to create a graphical representation of our data. It is straightforward and easy to visualize a trend in data when it is plotted as compared to just looking at the raw figures.

Syntax of Plot Function

Below are the syntax of Plot Function:

  • fplot (f)
  • fplot (f, xinterval)
  • fplot (funx, funy)
  • fplot (___, LineSpec)
  • fplot (___, Name, Value)
  • fp = fplot (___)

Let us now understand all the above-mentioned functions one by one:

1. fplot (f)

This will plot the graph defined by the function y = f(x). The plot is created over the default interval [-5, 5].

Let’s understand this function with the help of an example:

fplot (@(x)  x^2)

Here we have taken square function as the one which we need to plot. The output of our example will be as shown below:

matlab plot function

2. fplot (f, xinterval)

In the above example, the interval was defaulting, however, if we need the interval of our choice, we can use fplot (f, xinterval). We need to specify the interval as a 2-element vector in the form [xmin xmax]

Let’s understand this clearly with the help of an example:

fplot (@(x)  x^2, [0 3])

Here we have taken the same function as in the example above. For this example, we will take the interval 0 to 3. The output of our example will be as shown below:

matlab plot function

3. fplot (funx, funy)

This function will plot the 2 functions passed as arguments. Here we define 2 functions ‘at’ and ‘bt’ as follows:

at = @(t) cos(2*t);
bt = @(t) sin(1*t);

The output of the final function fplot (at, bt), will be

matlab plot function

4. fplot (___, LineSpec)

This function is used to get the marker symbol, line style or color of the plotline as per the choice of user. i.e user can decide how he/she wants to visualize the final output.

For example, if we need to plot a graph of red color, we will pass ‘r’ as the argument in any of the functions explained above.

Here is an example to understand this:

Example:

fplot (@(x)  x^2, ‘r’)

The output that we will get here will be a red color plot of square function:

matlab plot function

Similarly, we can use ‘b’ for blue color and ‘y’ for yellow color.

5. fplot (__, name, value)

This function is used to define properties of the line in the plot as per the pair of name-value passed in the argument. For example, if we pass ‘Linewidth’, 3 as an argument in any of the above examples, we will get a plot of width 3.

Here is an example to understand this:

fplot (__, name, value)

 6. fp = fplot (___)

This function is used to modify the properties of an existing plot. So, we can change the properties of a plot that is already created, by using this function.

Let us first draw plot for a sin wave using the function fp = fplot (@(x) sin(x))

Let us now understand various ways in which we can modify properties of our plot obtained from fp:

  • To change the line of the plot into a line with colons, we can use fp.LineStyle = ‘:’;
  • To change the color of the line, we can use fp.Color = ‘r’;
  • To get marker points on the plot, we can use fp.Marker = ‘x’;
  • To get the desired color of the markers, we can use fp.MarkerEdgeColor = ‘b’;

After implementing the above functions, our final output will be:

fp = fplot (___)

Conclusion

MATLAB is a system whose basic data element is an array that does not require any dimensioning. This allows us to solve computing problems, especially the problems with matrix & vector formulations. In addition to its computing powers, MATLAB also provides its users the ability to draw and visualize the data for better understanding and drawing inferences.

All this is done in a significantly less amount of time when compared to writing a program in a scalar and non-interactive language such as C.

Recommended Articles

This is a guide to MATLAB Plot Function. Here we discuss Where can MATLAB be used along with the Syntax and outputs. You can also go through our other suggested articles to learn more–

  1. Plot Function in R
  2. Matlab Features
  3. Pie Chart in MATLAB
  4. Colors in Matlab
  5. Complete Guide to Matlab Comet()
  6. Guide to How to Use Matlab?
  7. Algorithm to Implement Matlab LineWidth

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA

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

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

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

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW