% Write a sequence of frames to a compressed AVI file, peaks.avi.
% Prepare the new file.
writerObj = VideoWriter('peaks.avi');
%Generate initial data and set axes and figure properties.
Z = peaks; surf(Z);
%Setting the Renderer property to zbuffer or Painters works around limitations of getframe with the OpenGL® renderer on some Windows systems.
% Create a set of frames and write each frame to the file.
for k = 1:20
frame = getframe;