Filter löschen
Filter löschen

Graph animation: How do I keep points on graph?

5 Ansichten (letzte 30 Tage)
Kevin Carty
Kevin Carty am 7 Mär. 2020
Kommentiert: Kevin Carty am 8 Mär. 2020
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

Antworten (1)

Walter Roberson
Walter Roberson am 7 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 8 Mär. 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.
Kevin Carty
Kevin Carty am 8 Mär. 2020
I see. I figured out how to incorporate hold on and hold off into the code. Thanks!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by