EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • 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

Updated March 23, 2023

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.

ADVERTISEMENT
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Where can MATLAB be used?

Below are a few areas where we can use MATLAB:

  • 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
  8. Vector in Java | How to Create? | Examples
ADVERTISEMENT
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • 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

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

Let’s Get Started

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

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

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

Forgot Password?

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

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW