% Basic Movie Maker!

%Create the video file
vidfile = VideoWriter('testmovie.mp4','MPEG-4');
%This controls the framerate (speed) of the final video file
vidfile.FrameRate = 10;
open(vidfile);

%Create random pretty data
test = rand([100, 100, 30]);
test = movmean(test, 10, 1);
test = movmean(test, 10, 2);

%%%%%%%%%
%Animate!
%%%%%%%%%

%From 1 to the size of the third dimension
for frame = 1:size(test, 3)
    
    %Show the current frame
    pcolor(test(:,:,frame));shading flat
    %This command refreshes the figure
    drawnow

    %You can put a pause in if you'd like
    %This will only be visible when viewing from MATLAB, not from the saved
    %file
    pause(0.1)

    %These collect the frame and writes it to the video file
    %(gcf means get current figure)
    image = getframe(gcf);
    writeVideo(vidfile,image)

end

%This then closes and saves the file
close(vidfile)