MATLAB: How can I make the line animated for x2, y2

animatedlinemoving

x=[0 100 100 0 0]; y=[0 0 100 100 0]; x1=[50 50 50 50 50 60 70 80 80 80 80 80]; y1=[0 10 20 30 40 40 40 40 50 60 70 80]; plot(x,y,x1,y1)

Best Answer

x=[0 100 100 0 0]; y=[0 0 100 100 0];
x1=[50 50 50 50 50 60 70 80 80 80 80 80];
y1=[0 10 20 30 40 40 40 40 50 60 70 80];
plot(x,y);
hold on
for i = 1:length(x1)
plot(x1(1:i),y1(1:i),'r')
pause(0.2)
end