shg                 %show graph 
clf                 %clear plotting window
n=zeros(2001,1);                %index
x=(0:.001:2)';       %x values
j=1;

set (gcf,'doublebuffer','on')
y=zeros(2001,1);
h=plot(n,y,'.');
axis([0 2 -1 1])
axis square
stop=uicontrol('style','toggle','string','stop');

while get(stop,'value')==0
    y=cos(4*pi*x-10*n);
    set(h,'xdata',x,'ydata',y);
    drawnow;
    %j=j+.01;
    %n=cos(2*pi*j); 
    n=n+0.01;
end
