can I excute two plots in single ishghandle ?

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2022-6-3
while all(ishghandle(hdots))

更多回答(1 个)

omar th
omar th 2022-6-3
Thank you so much
  1 个评论
omar aljubory
omar aljubory 2022-6-7
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by