Animation with Slider Controls in GUIDE
object that handles updating the graphics. This example does not explore the technique,
but you can find information about programming timers in “Use a MATLAB Timer
Object”.
Make a Movie of the Animation
Selecting the Make movie check box before clicking Spin causes the application to
record each frame displayed in the while loop of the spinstopbutton_Callback
routine. When you select this check box, the animation runs more slowly because the
following block of code executes:
filming = handles.movie;
...
if ishandle(handles.axes1) && filming > 0 && filming < 361
globeframes(filming) = getframe; % Capture axes in movie
filming = filming + 1;
end
Because it is the value of a check box, handles.movie is either 0 or 1. When it is 1, a
copy (filming) of it keeps a count of the number of frames saved in the globeframes
matrix (which contains the axes CData and colormap for each frame). You cannot toggle
saving the movie on or off while the globe is spinning, because the while loop code does
not monitor the state of the Make movie check box.
The ishandle test prevents the getframe from generating an error if the axes is
destroyed before the while loop finishes.
When the while loop terminates, the callback prints the results of capturing movie
frames to the Command Window and writes the movie to a MAT-file:
if (filming)
filename = sprintf('globe%i.mat',filming-1);
disp(['Writing movie to file ' filename]);
save (filename, 'globeframes')
end
Note:Before creating a movie file with the UI, make sure that you have write permission
for the current folder.
The file name of the movie ends with the number of frames it contains. Supposing the
movie's file name is globe360.mat, you play it with: