Animating crank mechanism for loop troubles
Show older comments
When animating my slider crank, it plots an abundance of lines every increment through the loop. Is there a simple way to solve this? Thanks
%Create lengths for the slider crank
b = 3;
14 == 6;
15 == 26;
%Create for loop for the animation
for k = 0:0.1:4*pi
%Use input equations to get angles theta 11 and 12
th1 = +(acos((1/15)*sqrt((15)^2-(b+14*sin(k))^2)));
hold on
%Plot the crank arm
plot([0 14*cos(k)],[0 14*sin(k)],'o-','linewidth',3);
%Plot the second arm
plot([-35 35],[-5 5],'-','linewidth',3);
%Plot third arm
plot([14*cos(k) 14*cos(k)+15*cos(th1)],[14*sin(k) -b],'o-','linewidth',3);
hold off
%Create axis and pause for animation
axis([-35 35 -8 8]);
pause(0.1)
end
Answers (1)
darova
on 23 Jan 2020
Use this algorithm
hold on
for i = 1:n
h(1) = plot();
h(2) = plot();
pause(0.1)
delete(h)
end
hold off
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!