# can I excute two plots in single ishghandle ?

1 view (last 30 days)
omar th on 3 Jun 2022
Commented: omar aljubory on 7 Jun 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
% 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 on 3 Jun 2022
while all(ishghandle(hdots))

### More Answers (1)

omar th on 3 Jun 2022
Thank you so much
##### 1 CommentShowHide None
omar aljubory on 7 Jun 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).

R2018a

### Community Treasure Hunt

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

Start Hunting!