function moveatom(x1,y1,x2,y2) % move an atom from location (x1,y1) to (x2,y2) in nmove steps, % plotting along the way % nmove = 4; % intermediate locations to plot motion: dx = (x2-x1)/nmove; dy = (y2-y1)/nmove; x = x1 + (0:nmove)*dx; y = y1 + (0:nmove)*dy; for n=1:nmove plotatom(x(n),y(n),'w') % erase the old location by drawing in white plotatom(x(n+1),y(n+1),'b') % plot the new location by drawing in blue drawnow pause(.1) end