Home > custom > io > animate.m

animate

PURPOSE ^

function to simply animate timeslices in a 3D matrix

SYNOPSIS ^

function animate(X,varargin)

DESCRIPTION ^

 function to simply animate timeslices in a 3D matrix
 X is the 3D matrix with the frames to be animated stored in the first 2 
 dimensions and the 3rd dimension being the timeslices
 p is the pause between drawing the slices (optional, default 0.5 s)
 c is the colormap to use (optional, default = jet)
 example: animate(X,'p',0.2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function animate(X,varargin)
0002 % function to simply animate timeslices in a 3D matrix
0003 % X is the 3D matrix with the frames to be animated stored in the first 2
0004 % dimensions and the 3rd dimension being the timeslices
0005 % p is the pause between drawing the slices (optional, default 0.5 s)
0006 % c is the colormap to use (optional, default = jet)
0007 % example: animate(X,'p',0.2)
0008 
0009 %default params
0010 c='default';
0011 p=0.5;
0012 
0013 %parse inputs
0014 if isempty(varargin)~=1     % check if any arguments are given
0015     [m1,n1]=size(varargin);
0016     opts={'p';'c'};
0017     for i=1:n1;             % check which parameters are given
0018         indi=strcmpi(varargin{i},opts);
0019         ind=find(indi==1);
0020         if isempty(ind)~=1
0021             switch ind
0022                 case 1
0023                     p=varargin{i+1};
0024                 case 2
0025                     c=varargin{i+1};
0026             end
0027         end
0028     end
0029 end
0030 
0031 %
0032 cmin=min(X(:));cmax=max(X(:));
0033 figure
0034 for i = 1:size(X,3)
0035    imagesc(X(:,:,i)), colorbar
0036    colormap(c)
0037    title(['t=',num2str(i)])
0038    caxis([cmin cmax])
0039    pause(p)
0040    drawnow
0041 end

Generated on Tue 24-Feb-2009 19:14:50 by m2html © 2003