Using MATLAB Graphics     Search    Help Desk 

Movies

You can save any sequence of plots and then play the sequence back in a short movie. There are three steps to this process:

Visualizing an FFT

This example illustrates the use of movies to visualize the quantity fft(eye(n)), which is a complex n-by-n matrix whose elements are various powers of the nth root of unity, exp(i*2*pi/n).

Creating the Movie

The first step in creating a movie is to initialize the movie matrix. However, before calling moviein, you need to create an axes the same size as the one that will display the movie. Since this example displays data equally spaced around the unit circle, use the axis equal command to set the aspect ratio of the axes.

Call moviein to create a matrix large enough to hold the 16 frames that compose this movie. This step is not required, but if you do not initialize M, the code (but not the movie) runs more slowly because the storage for M is reallocated each time a new column is appended. Note that the axis equal statement must precede the M = moviein(16); statement to ensure MATLAB initializes M to the correct dimensions.

The statement,

prevents the plot function from resetting the axis shaping to axis normal each time it is called. See the axes NextPlot property for more information.

The getframe function with no arguments returns a pixel snapshot of the current axes in the current figure. The complexity of the plot does not affect the size of the frame, but the size of the current window does. Larger windows require more storage.

Note that getframe returns the contents of the current axes, exclusive of the axis labels, title, or tick labels. getframe(gcf) captures the entire interior of the current figure window.

If you plan to convert the MATLAB movie to another format (such as QuickTime) and you want to include the axis labels in this new format, you should capture the figure, not just the axes. If you are using moviein to pre-allocate the movie matrix, be sure to specify the same figure handle that you use with getframe.

Running the Movie

After generating the movie, you can play it back any number of times. To play it back 30 times, type

You can readily generate and smoothly play back movies with a few dozen frames on most computers. Longer movies require large amounts of primary memory or a very effective virtual memory system.

Full-Figure Movies

If you want to capture the contents of the entire figure window (for example, to include uicontrols in the movie), specify the figure's handle with both the moviein and getframe commands. For example, supose you want to add a slider to indicate the value of j in the previous example.



[ Previous | Help Desk | Next ]