can I excute two plots in single ishghandle ?

1 回表示 (過去 30 日間)
omar th
omar th 2022 年 6 月 3 日
コメント済み: omar aljubory 2022 年 6 月 7 日
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 Center および File ExchangeAnimation についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by