Graph animation: How do I keep points on graph?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi everyone I want to write some code that will animate a the points on a graph. The problem I am having is that I want the points to stay as the graph is being updated. The way I have it written right now is that the previous points dissapear on the graph as the for loop continues.
How do I fix this?
This is the question prompt:
Provide your commands to make a plot animation of the following data in the order that it appears. Each data point should be represented as a circle. The circles should remain while more data is added. Set the boundary of the graph window such that the right x boundary corresponds to the largest x-coordinate of any given coordinate pair, and the left x boundary corresponds to the smallest x-coordinate of any given coordinate pair. Do the same for the y boundaries. You may use predefined functions “min” and “max.”
This is what I have written.
x = [4 7 2 8 -3 -4 10 1 -5];
y = [8 2 -3 -9 1 0 2 1 7];
minx = min(x); maxx = max(x); miny = min(y); maxy = max(y);
for j = 1:length(x)
plot(x(j),y(j), 'o')
axis([minx maxx miny maxy]);
pause(1.0)
end
댓글 수: 0
답변 (1개)
Walter Roberson
2020년 3월 7일
hold on
if you want the points to keep accumulating so that over time there are more and more points on the graph.
See also animatedline()
댓글 수: 3
Walter Roberson
2020년 3월 8일
hold on specifically means that any previous graphics objects should not be erased so that as you add more graphics objects more and more will be visible.
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!