function [Mov, Movxyz] = sMovie(x,y,z, c, az, el)
% sMovie - makes a movie matrix of 3D points fitted with splines
%      Mov = sMovie(x,y,z)
%      Mov = sMovie(x,y,z, az, el)
%      Mov = sMovie(x,y,z, c, az, el)
%      [Mov, MovWire] = sMovie(x,y,z, c, az, el)
%	   x,y,z - m*n matrices of 3D points coordinates
%	     m - number of time frames
%	     n - number of points
%	   c - k*2 matrix. Each row contains numbers of two points that
%	       are connected in wire model
%	   az, el - azimuth and elevation of the view, default as in view(3)
%	   Mov - movie matrix, can be played with:
%	       movie(Mov); 
%	   MovWire - wire model movie, with points connected according to 
%	       matrix c
%
%  see also: sFitCart, moviein


view(3);
if nargin == 3, c=[]; [az,el] = view; end;
if nargin == 4, [az,el] = view; end;
if nargin == 5, c=[]; end;
if nargin<3 | nargin>6, 
   disp('sMovie: wrong number of parameters');
   return;
end; 

[m,n] = size(x);
r = sqrt(max(max(x.*x + y.*y + z.*z)));

clf;  axis([-r r -r r -r r]); axis('square'); axis('off');
Mov = zeros(size(getframe,1), m);

for t = 1:m,
   sM = sFitCart( x(t,:)', y(t,:)', z(t,:)' , 16);
   axis([-r r -r r -r r]); axis('square'); axis('off');
   view(az,el);
   Mov(:,t) = getframe;
end;   

if nargout <= 1, return; end;
% Movxyz = moviein(m);
clf;  axis([-r r -r r -r r]); axis('square'); axis('off'); view(az,el);
Movxyz = zeros(size(getframe,1), m);


for t = 1:m,
   plot3( x(t,:)', y(t,:)', z(t,:)' , 'o' );
   Mx = [ x(t,c(:,1)) ; x(t,c(:,2)) ] ;
   My = [ y(t,c(:,1)) ; y(t,c(:,2)) ] ;
   Mz = [ z(t,c(:,1)) ; z(t,c(:,2)) ] ;
   H = line(Mx,My,Mz);
   axis([-r r -r r -r r]); axis('square'); axis('off');
   view(az,el);
   Movxyz(:,t) = getframe;
end;

return;


