2017-02-26 9 views
1
count = 1;        
R_Ball = 2; 
initpos.x = 0; 
initpos.y = 2.4; 
initvel.x = 2; 
initvel.y = 4; 
gravity.x = 0; 
gravity.y = 9.81; 
restitution = 0.7; 
GroundBall_friction = 0.2; 
dt = 0.001; 
pos.x = initpos.x; % initial position 
pos.y = initpos.y; % initial position 
vel.x = initvel.x; % initial velocity-x 
vel.y = initvel.y; % initial velocity-y 
t_arc = linspace(0,(2*vel.y)/gravity.y,2000); 
for k = 1:2000 

%Updating the ball's position 
vel.x = vel.x; 
vel.y = vel.y - gravity.y*t_arc(k); 
pos.x = pos.x + vel.x*t_arc(k); 
pos.y = pos.y + vel.y*t_arc(k) - (1/2)*gravity.y*(t_arc(k).^2); 
if vel.y < 0 && pos.y < 0 
vel.y = (-1)*(restitution)*vel.y; 
vel.x = vel.x + GroundBall_friction*(restitution - 1)*vel.x; 
end 
pos.y = max(0, pos.y); 
clf; 
subplot(2,1,1) 
hold on 
line([0 30],[0 0]); 
rectangle('position', [pos.x pos.y R_Ball R_Ball],'Curvature',[1 1],'FaceColor','r'); 
posyy(count) = pos.y; 
plot(posxx + 1/2*R_Ball, posyy + 1/2*R_Ball,'b'); 
axis([0 30 0 10]); 
hold off 
subplot(2,1,2) 
hold on 
velyy(count) = vel.y; 
velxx(count) = vel.x; 
plot(posxx,velxx,'r','LineWidth',2); 
plot(posxx,velyy,'b','LineWidth',2); 
count = count+1; 
legend('Velocity.X','Velocity.Y'); 
hold off 
axis([0 30 -10 10]); 
%Refresh rate 
pause(dt) 
end 
% save video as .mp4; 
myVideo = VideoWriter('Boucing_Ball','mpeg-4'); 
myVideo.FrameRate = 60; % frames per second 
open(myVideo); 
writeVideo(myVideo,); 
close(myVideo); 

Ich weiß nicht, wie ich dieses Problem lösen kann. Ich möchte diese Animation exportieren und mit der VideoWriter-Funktion im MP4-Format speichern. Aber ich bin neu beim Schreiben von Animationen, so dass jede Hilfe geschätzt wird.Exportieren und Speichern einer Animation als Videodatei

Antwort

0

Der Code, wie es der folgende Fehler gibt:

Undefined function or variable 'posxx'

sollten Sie den folgenden Code hinzu (vor Zeile 18): posxx=0;

In diesem Thread Approaches to create a video in matlab Sie Informationen erhalten können, wie um ein Video mit writeVideo zu erstellen. Sie sollten den aktuellen Frame abrufen und speichern und dann die Funktion aufrufen.

Verwandte Themen