Animation in Matlab
|If we have some data representing a system
or a function at several time intervals, we may want to take advantage
of Matlab’s simple
animation capabilities. We're going to expose
the basic method or algorithm for animations.
In this example we’re going to work with just three special
The idea is to store every figure as a frame of the
‘movie’, with each frame stored as a column vector of a matrix, an then
play all the frames on the screen.
we initialize the matrix that will keep the frames, with the
number of frames to
with this instruction we keep the information of a given figure and
temporary matrix with information.
times, FPS): this is used to play the movie after
its generation. Parameter
‘matrix’ is the saved data, ‘times’ the number of times that the movie
played back, and ‘FPS’ means ‘frames per second’ (the default is 12).
try this simple animation example:
Define number of frames
Initialize matrix using 'moviein'
Generate frames with any plotting function.
% We use a cosine with variable frequency.
= 0 :
.01 : 6;
f = 1;
for i = 1 :
= f * 1.25; w = 2 * pi * f;
every frame with 'getframe'
and load the appropriate % matrix.
i) = getframe;
Save the matrix so that this movie can be loaded later
This is the first frame
of the recording:
can play back the movie:
Play the movie once, 2 FPS.
being played back...')
This is the last frame of
Animation' to 2D Menu