Graph animation: How do I keep points on graph?
古いコメントを表示
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
回答 (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 件のコメント
Kevin Carty
2020 年 3 月 8 日
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.
Kevin Carty
2020 年 3 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Animation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!