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
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??
채택된 답변
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198688/0000%20Screenshot.png)
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!