Creating a gif file out of an animation

1 次查看(过去 30 天)
Hi there,
i have a skript with an animation as output. i want to automatically save the animation as an video file on my laptop. what do i need to do?
thanks a lot for your help.
% raemliches Doppelpendel mit bushings
clear, close all
% Koerper 1 und 2 (homogene Quader)
a1 = 0.009; b1 = 0.009; c1 = 0.5 ; % Abmessungen 1 [m]
a2 = 0.009; b2 = 0.009; c2 = 0.5 ; % Abmessungen 2 [m]
par.grav0 = [ 0; 0; -9.81 ]; % Erbeschleunigung [m/s^2]
gpm =0.051; % Gewicht pro Meter
%Koerper3,
% Massen [kg]
par.mass1 = gpm*a1;
par.mass2 = gpm*a2;
% Traegheitstensoren 1+2 (Diagonalform) [kgm^2]
par.Theta1 = par.mass1/12*diag([b1^2+c1^2; c1^2+a1^2; a1^2+b1^2]);
par.Theta2 = par.mass2/12*diag([b2^2+c2^2; c2^2+a2^2; a2^2+b2^2 ]);
% Bushing B1: Umgebung / Koerper 1
par.riPi1= [ 0; 0; 0 ]; % Umgebung (Ursprung 0)
par.rjQj1= [ -a1/2 ; -b1/2; -c1/2 ]; % Koerper 1 (Eckpunkt)
par.FV01 = [ 0; 0; 0]; % Vorspannung [N]
par.CB1 = diag([ 10000; 10000; 10000 ]); % Steifigkeit [N/m]
par.DB1 = diag([ 0.2; 0.2; 0.2 ]); % Daempfung [N/(m/s)]
% Bushings 2: Koerper 1 / Koerper 2
par.riPi2= [ -a1/2 ; -b1/2; c1/2 ]; % Koerper 1 (Eckpunkt)
par.rjQj2= [ -a2/2 ; -b2/2; -c2/2 ]; % Koerper 2 (Eckpunkt)
par.FV02 = [ 0; 0; 0]; % Vorspannung [N]
par.CB2 = diag([ 10000; 10000; 10000 ]); % Steifigkeit [N/m]
par.DB2 = diag([ 0.2; 0.2; 0.2 ]); % Daempfung [N/(m/s)]
% Anfangs-Orientierung (Koerper 1 und 2 achsenparallel)
pE10=[ 1; -0.3; 0; 0 ]; A01=uty_A0K_EP(pE10);
pE20=[ 1; -0.3; 0; 0 ]; A02=uty_A0K_EP(pE20);
% konsistente Lage Massenmittelpunkte
r010 = par.riPi1 - A01*par.rjQj1;
r020 = r010 + A01*par.riPi2 - A02*par.rjQj2;
% Geschwindigkeiten (stossfreies Loslassen)
v010 = [ 0; 0; 0 ]; om011 = [ 0; 0; 0 ];
v020 = [ 0; 0; 0 ]; om022 = [ 0; 0; 0 ];
% Zeitsimulation
tspan = [0,0.0002];
x0=[r010;pE10;v010;om011; r020;pE20;v020;om022];
[t,xout] = ode45(@(t,x) K3_mks_elastisch_2_f(t,x,par),tspan,x0);
% Animation
[t,xout] = ode45(@K3_mks_elastisch_2_f,1:1/100:2.5,x0,[],par);
hf = figure;
set(hf,'units','normalized' ...
,'Position',[0.200 0.050 0.600 0.900] ...
,'Name','MKS Animation' ...
,'NumberTitle','off' ...
,'MenuBar','none' ...
,'Color',[0.99 0.99 0.99] ...
,'DoubleBuffer','on' )
% Quader definieren
[Q_P1,Q_F1,Q_N1,Q_C1] = uty_ani_quader_def(a1,b1,c1);
[Q_P2,Q_F2,Q_N2,Q_C2] = uty_ani_quader_def(a2,b2,c2);
% Blickrichtung
a=max([a1,a2,b1,b2,c1,c2]);
Camera_Pos=[5;3;2]*a;
Camera_Target=[0;0;0];
e_P=Camera_Target-Camera_Pos;
% Ortsvektoren und Euler-Parameter
r1x=xout(:, 1); r1y=xout(:, 2); r1z=xout(:, 3);
r2x=xout(:,13+1); r2y=xout(:,13+2); r2z=xout(:,13+3);
e10=xout(:, 4); e11=xout(:, 5); e12=xout(:, 6); e13=xout(:, 7);
e20=xout(:,13+4); e21=xout(:,13+5); e22=xout(:,13+6); e23=xout(:,13+7);
for i=1:length(t)
[A01,~,~] = uty_A0K_EP([e10(i);e11(i);e12(i);e13(i)]);
r1 = [r1x(i); r1y(i); r1z(i) ];
[A02,G,L] = uty_A0K_EP([e20(i);e21(i);e22(i);e23(i)]);
r2 = [r2x(i); r2y(i); r2z(i) ];
plot3(0,0,0)
hold on
% laufende Zeit
ht=text(a,-a,0.1*a,['t=',num2str(round(100*t(i))/100)]);
set(ht,'Fontsize',20)
% Quader zeichnen
uty_ani_quader_draw(r1,A01,e_P,Q_P1,Q_F1,Q_N1,Q_C1)
uty_ani_quader_draw(r2,A02,e_P,Q_P2,Q_F2,Q_N2,Q_C2)
% Koordinatenachsen
plot3(5*[-a,a],[0,0],[0,0],'r')
plot3([0,0],5*[-a,a],[0,0],'g')
plot3([0,0],[0,0],5*[-a,a],'b')
set(gca,'CameraPosition',Camera_Pos);
set(gca,'CameraTarget',Camera_Target);
set(gca,'CameraViewAngle',25)
%set(gca, getframe)
axis('equal'), axis('off')
hold off
pause(1/200)
end

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2022-1-14
I had a great experience using gif from the file exchange to convert a series of plots into a gif-animation. Simple to use does what it says on the tin, gif-file reasonably sized. The file exchange it the place to look for solutions to your problems - most of the time you'll find something that solves or partly solves your problem or at least helps significantly towards a solution.
HTH

类别

Help CenterFile Exchange 中查找有关 Waves 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by