from Learn Basic Plotting Principles by Husam Aldahiyat
Powerpoint Slides on the fundamentals of plotting and using the function line() with animation.

slide60
function slide60
	
	figure('units','normalized',...
		'position',[0.1 .3 .5 .5],...
		'color',[ 1 1 1],...
		'menubar','none',...
		'name','Example',...
		'numbertitle','off');
	
	axes('units','normalized',...
		'position',[ .5 .4 .4 .5]);
	
	L1=line([1 3],[3 3]);
	set(L1,'linewidth',2,...
		'color',[0 0 0])
	
	L2=line([3 4],[3 3]);
	set(L2,'linewidth',2,...
		'color',[1 0 0])
	
	L3=line([4 6],[3 3]);
	set(L3,'linewidth',2,...
		'color',[0 1 0])
	
	axis([-4 7 0 8])
	
	s1=uicontrol('style','slider',...
		'units','normalized',...
		'position',[ .1 .1 .2 .1],...
		'min',0,...
		'max',2*pi,...
		'value',0,...
		'callback',@changes);
	
	tx1=uicontrol('style','text',...
		'units','normalized',...
		'position',[ .1 .6 .1 .05 ],...
		'string','0');
	tx2=uicontrol('style','text',...
		'units','normalized',...
		'position',[ .1 .5 .1 .05 ],...
		'string','0');
	tx3=uicontrol('style','text',...
		'units','normalized',...
		'position',[ .1 .4 .1 .05 ],...
		'string','0');
	
	L=sqrt((4-3)^2+(3-1)^2);
	LL2=1;
	LL3=2;
	
	function changes(varargin)
		
		t1=get(s1,'value');
		t2=t1*2;
		t3=t1*4;
		
		set(tx1,'string',num2str(t1*180/pi))
		set(tx2,'string',num2str(t2*180/pi))
		set(tx3,'string',num2str(t3*180/pi,4))
		
		set(L1,'xdata',[ 1 1+L*cos(t1)],...
			'ydata',[3 3+L*sin(t1)])
		
		set(L2,'xdata',[1+L*cos(t1) 1+L*cos(t1)+LL2*cos(t2)],...
			'ydata',[3+L*sin(t1) 3+L*sin(t1)+LL2*sin(t2)])
		
		set(L3,'xdata',[ 1+L*cos(t1)+LL2*cos(t2) 1+L*cos(t1)+LL2*cos(t2)+LL3*cos(t3)],...
			'ydata',[3+L*sin(t1)+LL2*sin(t2) 3+L*sin(t1)+LL2*sin(t2)+LL3*sin(t3)])
		
	end			
	
end

Contact us at files@mathworks.com