Getting Started Previous page   Next Page

Animations

MATLAB provides three ways of generating moving, animated graphics:

Erase Mode Method

Using the EraseMode property is appropriate for long sequences of simple plots where the change from frame to frame is minimal. Here is an example showing simulated Brownian motion. Specify a number of points, such as

and a temperature or velocity, such as

The best values for these two parameters depend upon the speed of your particular computer. Generate n random points with (x,y) coordinates between -1/2 and +1/2:

Plot the points in a square with sides at -1 and +1. Save the handle for the vector of points and set its EraseMode to xor. This tells the MATLAB graphics system not to redraw the entire plot when the coordinates of one point are changed, but to restore the background color in the vicinity of the point using an exclusive or operation:

Now begin the animation. Here is an infinite while loop, which you can eventually exit by typing Ctrl+c. Each time through the loop, add a small amount of normally distributed random noise to the coordinates of the points. Then, instead of creating an entirely new plot, simply change the XData and YData properties of the original plot:

See how long it takes for one of the points to get outside the square and how long before all the points are outside the square.


Previous page  Finding the Handles of Existing Objects Creating Movies Next page

© 1994-2005 The MathWorks, Inc.