Z = peaks; % 49 by 49 by default
surf(Z)
axis tight
set(gca,'nextplot','replacechildren');
for j = 1:20
surf(sin(2*pi*j/20)*Z,Z)
F(j) = getframe(gcf);
imwrite(F(j).cdata,sprintf('file%d.png',j),'png');
end
movie(F,20) % Play the movie twenty times
