Home

Getting Animation Automatically with a comet Plot

|
Updated:  
2016-03-26 08:24:54
|
From The Book:  
MATLAB For Dummies
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 author:

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.