First off, I would like to thank all who contribute.

I want to animate a line, with a marker at the end of it, from the origin to the XYZ values along a trajectory. My trajectory contains 2000 XYZ values and moves in a semi circle. However, I can't seem to get the previous line to erase. In other words, Matlab draws the line at every XYZ value. Please check my code and tell me what I am doing wrong.

```
figure(1);
grid on;
xlim([-2.5,2.5]);
xlabel('X Axis');
ylim([-2.5,2.5]);
ylabel('Y Axis');
zlim([-2.5,2.5]);
zlabel('Z Axis');

set(gcf,'Renderer','OpenGL');
h = plot(x(1),y(1),z(1),0,'o','MarkerSize',10,'MarkerFaceColor','b');
set(h,'EraseMode','normal');

i = 1;

while i <= length(x)  
  set(h,'XData',x(i));
  set(h,'YData',y(i));
  set(h,'ZData',z(i));
  line([0 x(i)],[0 y(i)],[0 z(i)],'LineWidth',2,'EraseMode','normal');
  drawnow;
  i = i + 1;
end

```