How do I create a time-lapse video of a 3D plot?
32 次查看(过去 30 天)
显示 更早的评论
I have a recording of the trajectory of the two feet of a person, given as two time series of 3D coordinates. (two matrices of Nx3, with N being the number of samples). The feet are modeled as points in 3D space. I want to create a video that shows the movement of the feet over time.
What would be the best way of doing this in MATLAB?
0 个评论
采纳的回答
Kevin Holly
2023-6-28
编辑:Kevin Holly
2023-6-28
One way is to run a similar code as shown below in Live Editor. It will automatically create a video from the for loop that you can export.
matrix = rand(10,3);
matrix2 = rand(10,3);
ii=1;
foot1 = scatter3(matrix(ii,1),matrix(ii,2),matrix(ii,3),'filled','r');
hold on
foot2 = scatter3(matrix2(ii,1),matrix2(ii,2),matrix2(ii,3),'filled','g');
xlim([0 1])
ylim([0 1])
zlim([0 1])
for ii = 2:size(matrix,1)
foot1.XData = matrix(ii,1);
foot1.YData = matrix(ii,2);
foot1.ZData = matrix(ii,3);
foot2.XData = matrix2(ii,1);
foot2.YData = matrix2(ii,2);
foot2.ZData = matrix2(ii,3);
drawnow
end
v = VideoWriter('NameYourVideo.avi');
v.FrameRate = 1;
open(v);
for ii = 2:size(matrix,1)
foot1.XData = matrix(ii,1);
foot1.YData = matrix(ii,2);
foot1.ZData = matrix(ii,3);
foot2.XData = matrix2(ii,1);
foot2.YData = matrix2(ii,2);
foot2.ZData = matrix2(ii,3);
drawnow
frame = getframe(gca); %Note if you use gca (get current axis), make sure it doesn't change size - x, y, and z limits were defined above in this example to prevent this.
writeVideo(v,frame);
end
close(v)
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!