Recording high quality videos from Matlab plots

To record high quality video use export_fig method to generate antialiased bitmap out of the current plot and construct a video frame out of it. To render any size of plot hide the plot window and set the window size. To prevent plot cropping use -nocrop option for export_fig.

Example code:

aviObject = avifile('myVideo.avi');
writerObj.FrameRate = 20; % Optional
for i=0:100
    x=cos(0:0.02:10*pi)+(0:0.02:10*pi)/pi*(1+sin(i/100*pi*4))*2;
    y=sin((0:0.02:10*pi));
    plot(x,y,'linewidth',2);
    axis([-3,50,-1.2,1.2]);
    drawnow;
    set(gcf,'Visible', 'off', 'color', [1,1,1], 'Position', [1, 1, 1024,768]); 
    I=export_fig('-nocrop');
    F = im2frame(I);
    aviObject = addframe(aviObject,F);
    i
end
close;
aviObject = close(aviObject);
Advertisements