clear all; close all; writerObj = VideoWriter('Vid_ellipse2.avi'); % Name it. writerObj.FrameRate = 10; % How many frames per second. open(writerObj); N= 250; dt = 2*pi/N; subplot(2,4,2:3) t=0:dt:2*pi; x= cos(t-pi/4); y= sin(t); plot(x,y,'k','linewidth',3); axis equal xlim([-1.5,1.5]); ylim([-1.5,1.5]); subplot(2,2,3); plot(0,0); xlim([0,2*pi]); ylim([-1,1]); axis on; title('$\cos (x-\pi/4)$','Interpreter','latex','fontsize',16); subplot(2,2,4); plot(0,0); xlim([0,2*pi]); ylim([-1,1]); axis on; title('$\sin x$','Interpreter','latex','fontsize',16); mat1= linspace(-1.5,1.5,N); for i=1:length(t) subplot(2,4,2:3); if i >1 plot(x(i-1),y(i-1),'wo','MarkerSize',9); plot(x,y,'k','linewidth',3); plot(x(i-1)+0*mat1,mat1,'w','linewidth',2); plot(mat1, y(i-1)+0*mat1,'w','linewidth',2); end hold on plot(x(i),y(i),'go','MarkerSize',9); plot(x(i)+0*mat1,mat1,'b--','linewidth',2); plot(mat1, y(i)+0*mat1,'r--','linewidth',2); subplot(2,2,3); hold on plot(t(i),x(i),'b.','MarkerSize',3); subplot(2,2,4); hold on plot(t(i),y(i),'r.','MarkerSize',3); shg frame = getframe(gcf); % 'gcf' can handle if you zoom in to take a movie. writeVideo(writerObj, frame); end; close(writerObj);