How do I create a time-lapse video of a 3D plot?

35 次查看(过去 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?

采纳的回答

Kevin Holly
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
Or you can use writeVideo and getframe function
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 个评论
Kevin Holly
Kevin Holly 2023-6-29
If it worked, I would appreciate it if you would accept the answer.
Etay Kalifa
Etay Kalifa 2023-6-29
would you happen to know how I could add a time stamp to the video based on the sample rate?

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by