How to plot data point by point and erasing the last one?
이전 댓글 표시
Hello, I need to plot my data point by point, but I also need just one point on the plot (when new point arrived the one before to disappear). That is my code everything works good I just want to fix that:
y=[1,3,2,3,3];
n=numel(y)
figure
xlim([0 2])
ylim([0 2])
grid on
hold on
for ii=1:n
if y(ii)<1.1
scatter(0.5,0.5),hold on
pause(1)
else if y(ii)<2.2
scatter(1.5,1.5),hold on
else
scatter(0.5,1.5)
pause(1)
end
end
end
채택된 답변
추가 답변 (1개)
Steven Lord
2022년 9월 26일
Instead of creating two new scatter plots each step (one to cover the previous point in white, the other to create the new point) just update the coordinates of the point.
x = 0:360;
y = sind(x);
h = plot(x(1), y(1), 'o');
axis([0 360 -1 1])
for k = 2:numel(x)
drawnow expose
h.XData = x(k);
h.YData = y(k);
end
카테고리
도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!