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

32 Ansichten (letzte 30 Tage)
Etay Kalifa
Etay Kalifa am 28 Jun. 2023
Kommentiert: Etay Kalifa am 29 Jun. 2023
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?

Akzeptierte Antwort

Kevin Holly
Kevin Holly am 28 Jun. 2023
Bearbeitet: Kevin Holly am 28 Jun. 2023
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 Kommentare
Kevin Holly
Kevin Holly am 29 Jun. 2023
If it worked, I would appreciate it if you would accept the answer.
Etay Kalifa
Etay Kalifa am 29 Jun. 2023
would you happen to know how I could add a time stamp to the video based on the sample rate?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by