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 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