clear all;
clc;
x=[-3:0.1:3];
y=[-3:0.1:3];
t=[0:0.1:5];
hFigure = figure;
numberOfFrames = length(t);
allTheFrames = cell(numberOfFrames,1);
vidHeight = 344;
vidWidth = 446;
allTheFrames(:) = {zeros(vidHeight, vidWidth, 3, 'uint8')};
allTheColorMaps = cell(numberOfFrames,1);
allTheColorMaps(:) = {zeros(256, 3)};
myMovie = struct('cdata', allTheFrames, 'colormap', allTheColorMaps);
set(gcf, 'renderer', 'zbuffer');
[x, y] = meshgrid(-3:.1:3,-3:.1:3);
for frameIndex = 1 : numberOfFrames
z = exp(-(x-t(frameIndex)).^2-(y-t(frameIndex)).^2);
cla reset;
surf(x,y,z);
axis('tight')
zlim([0, 1]);
caption = sprintf('Frame #%d of %d, t = %.1f', frameIndex, numberOfFrames, t(frameIndex));
title(caption, 'FontSize', 15);
drawnow;
thisFrame = getframe(gca);
myMovie(frameIndex) = thisFrame;
end
message = sprintf('Done creating movie\nDo you want to play it?');
button = questdlg(message, 'Continue?', 'Yes', 'No', 'Yes');
drawnow;
close(hFigure);
if strcmpi(button, 'No')
return;
end
hFigure = figure;
title('Playing the movie we created', 'FontSize', 15);
axis off;
movie(myMovie);
uiwait(helpdlg('Done with demo!'));
close(hFigure);
Best Answer