Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

The code runs, but imediately deletes the animation and does not update

조회 수: 1 (최근 30일)
Matthew Palermo
Matthew Palermo 2019년 12월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
I am modeling a knuckle-link linkage system with a crank-slider and I am trying to get this animated plot for velocity and to show the motion. The code runs and gives the inital positions of everything, but then it deletes itself and does not update the positions.
clear
clc
A = 8.25; %in
B = 48;
C = 42;
D = 20;
t = 0:0.01:20; %sec
omega = 5.0265; %rad/sec
theta = omega*t;
phi = cot(theta);
P1_pos = [56.25;43.1];
P2_pos = [56.25-A*cos(theta);43.1-A*sin(theta)];
P4_pos = C*[0;1];
P5_pos = [0*sin(theta);-D*cos(phi)]; %P5_pos = D*[0;-1+sin(theta)];
P3_pos = [sin(phi);cos(phi)]; %P3_pos = [C + B*cos(a+b); B*sin(a+b)];
P5x = P5_pos(1,:);
P5y = P5_pos(:,1);
P5vx = diff(P5x);
P5vy = diff(P5y);
P5v = sqrt(P5vx.^2 + P5vy.^2);
for i = length(t)
ani = subplot(2,1,1);
P1_pos_cir = viscircles(P1_pos',0.05);
P2_pos_cir = viscircles(P2_pos(:,i)',0.05);
P3_pos_cir = viscircles(P3_pos(:,i)',0.05); %P3_pos_cir = viscircles(P3_pos(:,i)',0.05);
P4_pos_cir = viscircles(P4_pos',0.05);
P5_pos_cir = viscircles(P5_pos(:,i)',0.05);
barA = line([P1_pos(1) P2_pos(1,i)],[P1_pos(2) P2_pos(2,i)]);
barB = line([P2_pos(1,i) P3_pos(1,i)],[P2_pos(2,i) P3_pos(2,i)]);
barC = line([P4_pos(1) P3_pos(1,i)],[P4_pos(2) P3_pos(2,i)]);
barD = line([P5_pos(1,i) P3_pos(1,i)],[P5_pos(2,i) P3_pos(2,i)]);
axis(ani,'equal');
set(gca,'XLim',[-10 60],'YLim',[-30 60]);
str1 = 'P5';
P5_text = text(P5_pos(1,i),P5_pos(2,i)+0.4,str1);
pause(0.001);
delete(P1_pos_cir);
delete(P2_pos_cir);
delete(P3_pos_cir);
delete(P4_pos_cir);
delete(P5_pos_cir);
delete(barA);
delete(barB);
delete(barC);
delete(barD);
delete(P5_text);
% vel = subplot(2,1,2);
% plot(vel,t(1:i),P5v(1:i));
% set(vel,'XLim',[0 50], 'YLim',[0 10]);
% xlabel(vel,'time(s)');
% ylabel(vel,'Velocity of Press Block');
% grid on;
end
  댓글 수: 1
Adam
Adam 2019년 12월 5일
You seem to be explicitly telling it to delete everything!

답변 (1개)

Jeremy
Jeremy 2019년 12월 5일
delete(P1_pos_cir);
delete(P2_pos_cir);
delete(P3_pos_cir);
delete(P4_pos_cir);
delete(P5_pos_cir);
delete(barA);
delete(barB);
delete(barC);
delete(barD);
delete(P5_text);
I think this needs to be moved outside the for loop

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by