% beamtrajmov    

    makemov = 1 ;
    fnum = figure ;

    if makemov == 1
%        mov = avifile('C:\Documents and Settings\jolly\Desktop\rfqbeamtraj.avi','fps',25,'compression','None') ;
%        mov = avifile('/Users/jolly/Desktop/rfqbeamtraj.avi','fps',25,'compression','None') ;
        mov = avifile('C:\Documents and Settings\jolly\Desktop\lebtbeamtraj.avi','fps',15,'compression','None') ;
%        mov = avifile('/Users/jolly/Desktop/lebtbeamtraj.avi','fps',10,'compression','None') ;
    end

    for i = 1:length(timemat)

        figure(fnum), hold off ;
        set(fnum,'color','white') ;
        set(fnum,'Position',[10 80 1260 830]) ;

        subplot(2,3,[1:3]), xlabel(['z (m)']), ylabel(['y (mm)']) ;
%        axis([0 0.45 -5 5]) ;
        axis([0 1.8 -50 50]) ;

        subplot(2,3,4), xlabel(['x (mm)']), ylabel(['y (mm)']) ;
%        axis([-4 4 -4 4]) ; axis square ;
        axis([-50 50 -50 50]) ; axis square ;

        subplot(2,3,5), xlabel(['x (mm)']), ylabel(['x'' (mrad)']) ;
%        axis([-4 4 -400 400]) ; axis square ;
        axis([-50 50 -200 200]) ; axis square ;

        subplot(2,3,6), xlabel(['y (mm)']), ylabel(['y'' (mrad)']) ;
%        axis([-4 4 -400 400]) ; axis square ;
        axis([-50 50 -200 200]) ; axis square ;

        figure(fnum), gpttraj4plot(timemat,trajmat(1:500),colours,i) ;

        if makemov == 1
            frame(i) = getframe(fnum) ;
            mov = addframe(mov,frame(i)) ;
        else
            pause ;
        end

        close(fnum) ;

    end

    if makemov == 1
        mov = close(mov) ;
    end

    return