can I excute two plots in single ishghandle ?

1 visualización (últimos 30 días)
omar th
omar th el 3 de Jun. de 2022
Comentada: omar aljubory el 7 de Jun. de 2022
I am using ishghandle in while loop, So I want to animate two plots in single ishghandle, Can I animate hdots(1) and hdots (2) ? Thanks in advance
npts=1;center=[0 0];radius=1000;
% Initial direction/velocity of the points
velocity = 28.8/3.6;
% Create random starting locations within the circle
Totaltime =10;
theta = rand(npts, 1) * 2*pi;
g = 0.5 * radius + 0.5 * radius * rand(npts,1);
X_x=center(1)+g.*cos(theta);
Y_y=center(2)+g.*sin(theta);
XY = [X_x ,Y_y];
theta2 = rand(npts, 1) * 2*pi;
g2 = 0.5 * radius + 0.5 * radius * rand(npts,1);
X_x2=center(1)+g2.*cos(theta2);
Y_y2=center(2)+g.*sin(theta2);
XY2 = [X_x2 ,Y_y2];
hfig = figure('Color', 'w');
hax = axes('Parent', hfig);
hdots(1) = plot(XY(1,1),XY(1,2),'Parent', hax,'Marker', '.','Color', 'k','LineStyle', 'none','MarkerSize', 10);
hold(hax, 'on')
axis(hax, 'equal')
hdots(2) = plot(XY2(1,1),XY2(1,2),'Parent', hax,'Marker', '.','Color', 'r','LineStyle', 'none','MarkerSize', 10);
hold(hax, 'on')
axis(hax, 'equal')
% Plot the circl e as a reference
t = linspace(0, 2*pi, 100);
plot(radius * cos(t) + center(1),radius * sin(t) + center(2))
while ishghandle(hdots) % Can I animate hdots1 and hdots 2
direction = rand(npts, 1) * 2 *pi;
[XY, direction] = step(XY, direction, velocity, radius, center);
% Plot the dots as black markers
% Update the dot plot to reflect n ew locations
set(hdots, 'XData', XY(1,1), 'YData', XY(1,2))
% Force a r edraw
drawnow
pause (1)
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Jun. de 2022
while all(ishghandle(hdots))

Más respuestas (1)

omar th
omar th el 3 de Jun. de 2022
Thank you so much
  1 comentario
omar aljubory
omar aljubory el 7 de Jun. de 2022
Please, would you tell me if I can compare the current state with the previous state inside this “ while loop”
For example if i wanted to compare this if its greater or lesser than the previous X(current state) >= X(previous state).
Thanks in advance

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by