function get_convergence_movie(f,sequence_x,sequence_fx,nframes) % plots the real valued function f of one real variable together with % the sequence of points given by sequence_x and sequence_fx input % and produces a movie movie.avi with this plot where the points appear % one after another in the sequence using nframes frames. Two modes are possbile: % with you_can_see=1 all plots and the movie are displaied on screen; % with you_can_see=0 no plots are displaied on screen and the movie % will need to be played separately from the file movie.avi, % using any AVI movie player. %Revision 1.2 by Andrew Knyazev. Oct. 21, 2002. you_can_see = 1; %use 1 here is you run MATLAB in the graphics interactive mode, otherwise set 0 % note: 0 seems to give an error on our Linux systems min_x=min(sequence_x); max_x= max(sequence_x); %these are the limits for x npoints=500; %number of point to draw the function x = min_x:(max_x-min_x)/npoints:max_x; %function argument fx = feval(f,x); %function to draw if nframes > size(sequence_x,1)-2 fprintf('the requested number of movie frames %i is too large and \n will be reduced to %i to match the data \n',nframes,size(sequence_x,1)-2); nframes = size(sequence_x,1)-2; if nframes < 1 warning('No frames detected, no movie generated') return end end % see http://www.mathworks.com/support/tech-notes/1200/1204.shtml %These are unsuccessful attempts to reduce the color depth %set(0,'ScreenDepth',8) %map = colormap(hsv(8)); if you_can_see %you can and want to see the figures left=0; bottom=0; width=640; height=480; rect = [left, bottom, width, height]; hf=figure(1); set(1,'Position',rect); set(gca,'Xlim',[min_x max_x]); axis tight set(gca,'nextplot','replacechildren'); M = moviein(nframes); % for earlier versions of MATLAB (before Release 11/MATLAB 5.3) for k = 1:nframes plot(x,fx,'k'); title('Convergence sequence','fontsize',16) ylabel('function','fontsize',16) xlabel('argument','fontsize',16) grid on hold on plot(sequence_x(1:k+1),sequence_fx(1:k+1),'bo'); plot(sequence_x(k+2),sequence_fx(k+2),'r*'); drawnow; M(k) = getframe(gcf); %M(k) = im2frame(gcf,map); hold off end % Play the MATLAB movie once with fps=1 clf %to clear movie(hf,M,1,1) % movie2avi(M,'movie.avi','fps',1,'compression','None','colormap',colormap(hsv(8))); %creates the AVI movie from the MATLAB movie movie2avi(M,'movie.avi','fps',1,'compression','None'); else %you cannot or do not want to see the figures aviobj=avifile('movie.avi','fps',1,'compression','None'); %creates AVI file, test.avi hf = figure('visible','off'); %turns visibility of figure off left=0; bottom=0; width=640; height=480; rect = [left, bottom, width, height]; set(1,'Position',rect); set(gca,'Xlim',[min_x max_x]); hax=axes; for k=1:nframes plot(x,fx,'k','parent',hax); %puts image in invisible axes grid on title('Convergence sequence','fontsize',16) ylabel('function','fontsize',16) xlabel('argument','fontsize',16) hold on plot(sequence_x(1:k+1),sequence_fx(1:k+1),'bo','parent',hax); plot(sequence_x(k+2),sequence_fx(k+2),'r*','parent',hax); hold off aviobj=addframe(aviobj,hf); %adds frames to the AVI file end aviobj=close(aviobj); %closes the AVI file close(hf); %closes the handle to invisible figure end