How do I hold the second to last image of the simulation?

1 次查看(过去 30 天)
hold on
axis equal
axis off
b = 0:pi/40:pi/4;
c = 0:pi/20:pi/2;
P4vct=nan(numel(b),2);
for k = 1:numel(b)
P1=[-15,0];
P2=[-5,0];
plot([P1(1) P2(1)],[P1(2) P2(2)],'LineWidth',5,'Color','black');
A=[0,0];
h{1} = viscircles(A,5,'LineWidth',2,'Color','black');
B = A+[10*cos(b(k)-pi/4),10*sin(b(k)-pi/4)];
h{2} = viscircles(B,5,'LineWidth',2,'Color','green');
C = B+[10*cos(c(k)-pi/2),10*sin(c(k)-pi/2)];
h{3} = viscircles(C,5,'LineWidth',2,'Color','blue');
P3=C+[5*cos(c(k)-(pi/2)),5*sin(c(k)-(pi/2))];
P4=C+[15*cos(c(k)-(pi/2)),15*sin(c(k)-(pi/2))];
h{4} = plot([P3(1) P4(1)],[P3(2) P4(2)],'LineWidth',5,'Color','black');
P4vct(k,:) = P4;
h{5} = plot(P4vct(:,1),P4vct(:,2), '--','LineWidth',3,'Color','blue');
drawnow();
pause(0.5);
delete(vertcat(h{1:4}));
end
hold off
axis equal
axis off
  2 个评论
Walter Roberson
Walter Roberson 2018-12-10
"hold" it in what sense? You want the last two frames to be displayed on top of each other at the end, but during the main part of the loop only one frame is to be displayed at a time??
Allison Bushman
Allison Bushman 2018-12-10
The last frame ends up being my original line between P1 and P2 without the circles, but I would like the last frame to be of the circles aligned.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2018-12-10
At the bottom of the loop, only call delete() if it's not the last one:
if k < numel(b)
delete(vertcat(h{1:4}));
end
0000 Screenshot.png

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by