shg                 %show graph 
clf                 %clear plotting window
n=zeros(201,1);                %index
x=(-1:.01:1)';       %x values

%set (gcf,'doublebuffer','on')
y=zeros(201,1);
h=plot(n,y,'.');
axis([-1 1 -1 1])
axis square
stop=uicontrol('style','toggle','string','stop');

while get(stop,'value')==0
    y=cos(2*pi*n.*x);
    set(h,'xdata',x,'ydata',y);
    drawnow;
    n=n+.001; 
    
end
