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

조회 수: 20 (최근 30일)
Etay Kalifa
Etay Kalifa 2023년 6월 28일
댓글: Etay Kalifa 2023년 6월 29일
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에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by