%% View Figure Plots While Frames Are Calculated
% View the figure plots while they are calculated. Play the movie array once.
% Create a figure object h and initialize the surface plot. Customize the figure axes.

h = figure;
Z = peaks;
surf(Z)
axis tight manual
ax = gca;
ax.NextPlot = 'replaceChildren';

% Preallocate a 40-element array M to store the movie frames.

loops = 40;
M(loops) = struct('cdata',[],'colormap',[]);

% Capture each plot of function X as an individual frame and store them in M.

for j = 1:loops
    X = sin(j*pi/10)*Z;
    surf(X,Z)
    drawnow
    M(j) = getframe;
end

% Play the movie in M once.
% movie(M);
% Copyright 2020 The MathWorks, Inc.