Borrar filtros
Borrar filtros

Graph animation: How do I keep points on graph?

5 visualizaciones (últimos 30 días)
Kevin Carty
Kevin Carty el 7 de Mzo. de 2020
Comentada: Kevin Carty el 8 de Mzo. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Mzo. de 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 comentarios
Walter Roberson
Walter Roberson el 8 de Mzo. de 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 el 8 de Mzo. de 2020
I see. I figured out how to incorporate hold on and hold off into the code. Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by