Development Environment |
Exporting MATLAB Graphs in AVI Format
In MATLAB, you can save a sequence of graphs as a movie that can then be played back using the movie
function. You can export a MATLAB movie by saving it in MAT-file format, like any other MATLAB workspace variable. However, anyone who wants to view your movie must have MATLAB. (For more information about MATLAB movies, see the Animation section in the MATLAB Graphics documentation.)
To export a sequence of MATLAB graphs in a format that does not require MATLAB for viewing, save the figures in Audio Video Interleaved (AVI) format. AVI is a file format that allows animation and video clips to be played on a PC running Windows or on UNIX systems.
To export a sequence of MATLAB graphs as an AVI format movie, perform these steps:
avifile
function.
addframe
function.
close
function, overloaded for AVI files.
Note
To convert an existing MATLAB movie into an AVI file, use the movie2avi function.
|
For example, this code example exports a sequence of MATLAB graphs as the AVI file mymovie.avi
.
aviobj = avifile('mymovie.avi','fps',5); for k=1:25 h = plot(fft(eye(k+16))); set(h,'EraseMode','xor'); axis equal; frame = getframe(gca); aviobj = addframe(aviobj,frame); end aviobj = close(aviobj);
Note the following items in this code example:
avifile
function creates an AVI file and returns a handle to an AVI file object. AVI file objects support properties that let you control various characteristics of the AVI movie, such as colormap, compression, and quality. (See the avifile
reference page for a complete list.) avifile
uses default values for all properties, unless you specify a value. In the example, the call to avifile
explicitly sets the value of the frames per second (fps
) property.
for
loop to capture the series of graphs to be included in the movie. You typically use addframe
to capture a sequence of graphs for AVI movies. However, because this particular MATLAB animation uses XOR
graphics, you must call getframe
to capture the graphs and then call addframe
to add the captured frame to the movie. See the addframe
reference page for more information.
close
function to finish writing the frames to the file and to close the file.
Exporting Binary Data | Importing HDF Data |