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.
Open your copy of MATLAB.
The MATLAB application starts with the Command window displayed.
Type format compact and press Enter.
MATLAB displays the output of anything you type using the compact format.
Type Time = -pi:.01:pi; and press Enter.
The Time variable contains the individual intervals that MATLAB plots for you.
Type Y = sin(Time); and press Enter.
A new variable is created with the individual instance values needed to plot the diagram.
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.
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.
Close your copy of MATLAB.