how to animate two different plot at the same time
16 views (last 30 days)
Show older comments
I would like to animate both the following animation at the same time not one after the other
axis(gca,'equal')
axis([-24 24 -10 10])
cirx=[-0.5,-1.5,-1.75,-1.75,-1.5,-0.5,-1.5,-1.75,-2.0,-1.55];
ciry=[-0.5,1.5,2.5,2.75,2,1,-1,-1.75,-2.5,-2.65];
for p=1:10
ring= plot(cirx(p),ciry(p),'bo','Markersize',6);
pause(0.9);
delete(ring);
end
% crank
p1=[ 10 0];
rod=3;
slid=3.5;
k=1;
for ti=1:500
theta=k*(ti/10);
alfa= asin(rod*sin(theta)/slid);
p3= [rod*cos(theta)+slid*cos(alfa) 0];
p2= rod*[cos(theta) sin(theta)];
crank= line([p1(1) p2(1)+10],[p1(2) p2(2)]);
slider=line([p2(1)+10 p3(1)],[p2(2) p3(2)]);
pist= line([p3(1) p3(1) p3(1)],[p3(2) 3 -3]);
pause(0.1);
delete(crank);
delete(slider);
delete(pist);
end
0 Comments
Answers (1)
n33
on 11 Apr 2019
Edited: n33
on 11 Apr 2019
After some search on Google, I managed to plot 2 animated subplots simutaneously. Below is my solution in case anyone is directed to this post like I did and hopefully this is a little bit helpful to him.
% Simplest way
x = rand(1, 11); y = rand(1, 11);
z = rand(1, 11); a = rand(1, 11);
figure
for i = 1 : 10
subplot(211)
plot(x(i : i+1), y(i : i+1), '.-k');
hold on; % include this if you want to show plot history
subplot(212)
plot(z(i : i+1), a(i : i+1), '.-k');
drawnow;
pause(0.1);
end
% If you don't want to call "plot" interatively
x = rand(1, 11); y = rand(1, 11);
z = rand(1, 11); a = rand(1, 11);
figure
subplot(211)
p1 = plot(NaN, NaN, 'marker', 'o');
subplot(212)
p2 = plot(NaN, NaN, 'marker', 'd');
for i = 1 : 10
set(p1, 'xdata', x(i : i+1), 'ydata', y(i : i+1));
set(p2, 'xdata', z(i : i+1), 'ydata', a(i : i+1));
drawnow;
pause(0.1);
end
0 Comments
See Also
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!