Main Content

Record Animation for Playback

These examples show how to record animations as movies that you can replay.

Record and Play Back Movie

Create a series of plots within a loop and capture each plot as a frame. Ensure the axis limits stay constant by setting them each time through the loop. Store the frames in M.

for k = 1:16
	plot(fft(eye(k+16)))
	axis([-1 1 -1 1])
	M(k) = getframe;
end

Plot of the Fourier transform of sixteen different identity matrices

Play back the movie five times using the movie function.

figure
movie(M,5)

Capture Entire Figure for Movie

Create a colored panel in the figure, and place the axes in the panel before creating the plot. Capture the entire figure window by specifying the current figure (gcf) as an input argument to the getframe function.

f = figure;
p = uipanel(f,"Position",[0.1 0.1 0.8 0.8],...
    "BackgroundColor","w");
ax = axes(p);

for k = 1:16
    plot(fft(eye(k+16)))
    axis([-1 1 -1 1])
    u.Value = k;
    M(k) = getframe(gcf);
end

Plot of the Fourier transform of sixteen different identity matrices within a colored panel

Create a new figure and an axes to fill the figure window so that the movie looks like the original animation.

figure
axes("Position",[0 0 1 1])
movie(M,5)

See Also

| | | | | |

Related Examples

More About