animation: point following line in 2d plot
이전 댓글 표시
Hi, I think i have a fairly easy question but i just can't get it to work. I am trying to create a plot of a 2d line, and i want a point to slowly follow that line. My code so far is:
figure
plot(y)
t=(length(y)+1);
i=1;
while i<t
hold on
plot(i,y(i),'o m');
hold off
i=i+1;
pause(0.1);
end
The problem is that all the points are drawn, but how can i delete the previous point (y(i-1))? Thanks!
답변 (1개)
bym
2011년 10월 22일
here is one way:
x = 0:pi/50:2*pi;
y = sin(4*x);
plot(x,y)
hold on
h = plot(x(1),y(1),'mo','MarkerFaceColor','m',...
'YDataSource','Y',...
'XDataSource','X');
for t = 1:numel(x)
X = x(t);
Y = y(t);
refreshdata(h,'caller');
drawnow;
pause(.1);
end
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!