MATLAB For Dummies
Book image
Explore Book Buy On Amazon

MATLAB provides a few plots that create animated effects. One of the more interesting plots that naturally lends itself to presentations is the comet() plot. When you create a plot using this function, the beginning of the line forms the comet head, while the end of the line forms the tail.

As MATLAB performs the calculation and creates more points, the comet moves along its way until the plot is finished. It's an interesting effect that helps people see the manner in which the plots are created, which is especially helpful with time-related plots.

The following steps help you create a comet() plot.

  1. Open your copy of MATLAB.

    The MATLAB application starts with the Command window displayed.

    image0.jpg
  2. Type format compact and press Enter.

    MATLAB displays the output of anything you type using the compact format.

    image1.jpg
  3. Type Time = -pi:.01:pi; and press Enter.

    The Time variable contains the individual intervals that MATLAB plots for you.

    image2.jpg
  4. Type Y = sin(Time); and press Enter.

    A new variable is created with the individual instance values needed to plot the diagram.

    image3.jpg
  5. Type comet(Y); and press Enter.

    MATLAB draws the plot. However, notice the animation effect. The plot begins at the left side of the plot area and moves toward the right. The plot doesn't appear all at one time; instead, you see the plot being drawn.

    image4.jpg
  6. Type comet(Y); and press Enter again.

    Notice how MATLAB clears the display area and redraws the plot from scratch. The animation can be repeated in a loop for effect.

  7. Close your copy of MATLAB.

About This Article

This article is from the book:

About the book authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: