Graph animation: How do I keep points on graph?
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 7 Mar 2020
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 Comments
Walter Roberson
on 8 Mar 2020
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.
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!