function mat2anim(M, basename)

% create a series of colorized matrix plots.
% M        : 3d matrix (3rd dimension= time)
% basename : path and filename base. 
%            The frame number + '.png' are added automatically
%
% e.g. mat2anim(Corforecast, 'c:/tmp/frames/frame')
%      this creates files called c:/tmp/frames/frame0001.png ....


hold off
hold on

offset=length(M)-250;

s= size(M);

for frame= 1:s(3)

    sframe=['00000',num2str(frame)];
    sframe=sframe(end-3:end);
    filename=[basename,sframe,'.png'];
    mat= M(1:end,1:end,frame);


    pcolor(mat);
    caxis([0,1])
    colorbar
    title(['Day ',num2str(frame-offset)]);
    print('-r80', '-dpng', filename);

    

end
