I didn't analyze for a more efficient solution, but move
xdt=linspace(0,xdt,n);%Increments X and Y so graph can animate
ydt=linspace(0,ydt,n);
inside your loop, and index xdt(i) ydt(i) as elsewhere.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!