How to create animation ?
1 view (last 30 days)
Show older comments
I have written a code to solve differential equation of a simple pendulum. I tried creating animation of the same. But I am not getting properly. Please correct me.
clear all
close all
clc
%let theeta=y
L=1;
t=[0 20];
yo=[0 3];
[t,y]=ode45('simplependulum',t,yo)
figure(1)
plot(t,y(:,1))
xlabel('time')
ylabel('displacement')
figure(2)
plot(t,y(:,2))
xlabel('time')
ylabel('angular velocity')
O=[0 0];
axis(gca,'equal');
axis([-0.7 0.7 -0.7 0.2]);
grid on;
figure(3)
for i=1:length(t)
P=L*[sin(y(i,1)) -cos(y(i,1))]
O_circle=viscircles(O,0.01);
pend=line([O(1) P(1)],[O(2) P(2)]);
ball=viscircles(P,0.05);
pause(0.001);
if i<length(t)
delete(pend);
delete(ball);
delete(O_circle);
end
end
0 Comments
Answers (1)
Image Analyst
on 22 Dec 2018
See attached demo where I make a movie from different frames of surf() - the surface is changing in time.
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!