Sorry for my bad English :( hope you guys can understand what my problems are.
Fist this is my code of a double pendulum simulation.
close all;clear all; clc;
theta1 = -pi;
dtheta1 = -5;
theta2 = pi/2;
dtheta2 = 10;
m1 = 1;
m2 = 1.7;
r1 = 1.3;
r2 = 1;
g = 9.8;
duration = 5;
y0 = [theta1;dtheta1;theta2;dtheta2;m1;m2;r1;r2;g];
[t,y] = ode45(@eqns,[0 duration],y0);
theta1 = wrapToPi(y(:,1));
dtheta1 = y(:,2);
theta2 = wrapToPi(y(:,3));
dtheta2 = y(:,4);
fps = round(length(theta1)/duration);
X = zeros(length(theta1),3);
Y = zeros(length(theta1),3);
for i=1:length(theta1)
X(i,:)=[0,r1*sin(theta1(i)),r1*sin(theta1(i))+r2*sin(theta2(i))];
Y(i,:)=[0,-r1*cos(theta1(i)),-r1*cos(theta1(i))-r2*cos(theta2(i))];
end
mov = VideoWriter('Double Pendulum','MPEG-4');
set(mov,'FrameRate',fps,'Quality',100);
open(mov)
h = plot(0,0,'MarkerSize',30,'Marker','.','LineWidth',1.4);
range = 1.25*(r1+r2);axis([-range range -range range]); axis square;
xlabel('x');ylabel('y');title('Double Pendulum');
set(gca,'nextplot','replacechildren');
textlocation = range * 0.7;
hold on
for i=2:length(theta1)
set(h,'XData',X(i,:),'YData',Y(i,:));
plot([X(i-1,3) X(i,3)],[Y(i-1,3) Y(i,3)],'r')
plot(X(i,2),Y(i,2),'g')
frame = getframe;
writeVideo(mov,frame);
end
close(mov);
And here is the result, https://www.dropbox.com/s/7pyagcnhca6khb3/Double%20pendulum%20result.PNG
For some reason the labels and title aren't get recorded, and I also realize that the colour are really different from what I see in Matlab. I tried using 'Uncompressed AVI' instead of 'MPEG-4' is give me the best result in terms of colour and quality, but the file size is 50MB, with 'MPEG-4' the file size is only 560KB.
I want to know, is there any setting that will give me a a better coulor (closer to what I see in Matlab) with lower file size (I am quite happy with this mp4 quality) and the labels will get recorded.
Thanks a lot.