x=linspace(-10,10,100); M = repmat(struct('cdata',{[]},'colormap',{[]}),1,21); %Preallocates space %for movie structure M for j=1:21 t=(j-1)/5; u=exp(-(x-2*t).^2); plot(x,u); axis([-10,10,0,2]) xlabel('x') ylabel('u') M(j)=getframe(gcf); end axes('Position',[0 0 1 1]) movie(M,5) %This plays the movie 5 times. To see it play just once, use movie(M)