from High Speed PIV and Hotwire post processing by Anurag
High Speed PIV and hotwire post processing routines

[]=mkswmov(filename, fps, frm1, frm2)
function []=mkswmov(filename, fps, frm1, frm2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                                                  %%
%%   Copyright (C) 2005-2007  Anurag Singh                                                          %%
%%                                                                                                  %%
%%       This program/code snippet/file (hence forth refered as "library")                          %%
%%       is free software; you can redistribute it and/or                                           %%
%%       modify it under the terms of the GNU Lesser General Public                                 %%
%%       License as published by the Free Software Foundation; either                               %%
%%       version 2.1 of the License, or (at your option) any later version.                         %%
%%                                                                                                  %%
%%       This library is distributed in the hope that it will be useful,                            %%
%%       but WITHOUT ANY WARRANTY; without even the implied warranty of                             %%
%%       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                          %%
%%       Lesser General Public License for more details.                                            %%
%%                                                                                                  %%
%%       You should have received a copy of the GNU Lesser General Public                           %%
%%       License along with this library; if not, write to the Free Software                        %%
%%       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                  %%
%%                                                                                                  %%
%%   FILENAME:                                                                                      %%
%%      mkswmov.m                                                                                   %%
%%                                                                                                  %%
%%   AUTHOR:                                                                                        %%
%%                                                                                                  %%
%%      Anurag Singh,                                                                               %%
%%      MS, 2007                                                                                    %%
%%      Aerospace Engineering & Mechanics                                                           %%
%%      University of Minnesota - Twin Cities.                                                      %%
%%      Minneapolis, MN 55455 (USA)                                                                 %%
%%                                                                                                  %%
%%      (currently working at: Exa Corporation, Burlington, MA 01803)                               %%
%%                                                                                                  %%
%%   CONTACT/EMAIL:                                                                                 %%
%%                                                                                                  %%
%%      anurag@aem.umn.edu                                                                          %%
%%      anurag9@gmail.com                                                                           %%
%%                                                                                                  %%
%%   SOURCE CONTROL INFORMATION:                                                                    %%
%%      None (since I was planning on putting it under source control since it has                  %%
%%      reached the critical file system size. Would be a good thing to put it under                %%
%%      source control while making changes.                                                        %%
%%                                                                                                  %%
%%   DESCRIPTION:                                                                                   %%
%%                                                                                                  %%
%%       Need to add                                                                                %%
%%                                                                                                  %%
%%                                                                                                  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% USAGE:
%
%  mkswmov(filename, fps, frm1, frm2)
%
%  Input Arguments:
%     filename     filename into which movie will be saved
%     fps          frames per second
%     frm1         first frame
%     frm2         last frame
%
% Output: Movie file saved in the current name under the name <filename>
%
% EXAMPLE:
%  mkswmov('mymov.avi', 5, 1, 100)
%

global u_norm x y piv_ustd v capfreq sw2D stdsw2d delta_99 u_tau nu

if(nargin ~= 4)
   disp ('  ERROR: Insufficient arguments.');
   help mkswmov;
else

   mov     = avifile(filename)
   mov.fps         = fps;        % frames per second
   mov.compression = 'none';     % compresson info

   stdsw2d = mean(mean(std(sw2D(frm1:frm2,:,:))));

   for frame = frm1:frm2
      pcolor(x*u_tau/nu, y*u_tau/nu, squeeze(u_norm(frame,:,:))) % the squeeze is to squeeze down a 3d matrix (where one of the dimensions is one) to a 2d matrix
      caxis([-3*piv_ustd 3*piv_ustd]) % i am setting the colorbar based on the rms of the signal
      title(['time ', num2str(2*frame/capfreq, '%.5f'), ' s'])

      cb = colorbar('vert'); % display the colorbar
      shading interp; % interpolated shading
      lighting phong; % nice spline fit to the shading
      xlabel('x^{+} ->');
      ylabel('y^{+} ->');
      daspect([1 1 1]); % set aspect ration to one (equal x and y scale)

      % and to add quiver plots
      hold on
      %quiver(x, y, squeeze(u_norm(frame,:,:)),squeeze(v(frame,:,:)), 3, 'k') % the number scales the arrow length
      %quiver(x, y, squeeze(u_norm(frame,:,:)),squeeze(v(frame,:,:)), 1,'k') % the number scales the arrow length

%      contour(x,y,squeeze(sw2D(frame,:,:)),'linespec','-k');
      contour(x*u_tau/nu,y*u_tau/nu,squeeze(sw2D(frame,:,:)).*(squeeze(sw2D(frame,:,:))>2.4*stdsw2d),12);
      hold off;
      drawnow;
      F   = getframe(gca);
      mov = addframe(mov,F);
      
   end

   mov = close(mov);

end

Contact us at files@mathworks.com