Combine a video with animations of three subplots

22 visualizaciones (últimos 30 días)
Youngmin
Youngmin el 15 de Oct. de 2021
Editada: Youngmin el 17 de Oct. de 2021
Hello, I am trying to make a video file by combining a video with animations of three subplots. The subplots are position, velocity, and acceleration graphs of the video. However, I am struggling with two things: the size of the video in figure and saving the video with animations. I tried to create 3X2 subplots by putting the video on the left hand side and three graphs on the right hand side. But, I am not sure how to change the size of the video to the same height of sum of all three graphs.
Also, when I try to save the video, I kept having this warning and the video was not saved:
% Warning: No video frames were written to this file. The file may be invalid.
Video and data have the same frame numbers and frame rates. I have attached the script and the csv file of the data that I want to create the plots next to the video.
data = readtable('pva.csv');
inputVid=VideoReader('VJ.mov');
mergedobj = VideoWriter('compositevid','Motion JPEG AVI');
mergedobj.FrameRate = inputVid.FrameRate;
mergedobj.Quality=100;
open(mergedobj);
hfig = figure;
t = 0:(1/60):(162/60);
i = 1;
while hasFrame(inputVid)
singleFrame = readFrame(inputVid);
subplot(3,2,1),imagesc(singleFrame), axis off, axis equal;
subplot(3,2,2);
plot(t(i),data.Position(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Position(1:i),'-k');
axis([0 t(end) 0 max(data.Position)+0.2])
subplot(3,2,4);
plot(t(i),data.Velocity(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Velocity(1:i),'-k');
axis([0 t(end) -3 3])
subplot(3,2,6);
plot(t(i),data.Accleration(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Accleration(1:i),'-k');
axis([0 t(end) -18 18])
pause(0.1)
if i ~= length(t)
clf
i= i+1;
else
close(mergedobj)
end
end

Respuestas (1)

kunal gokhe
kunal gokhe el 15 de Oct. de 2021
Try this code below
data = readtable('pva.csv');
inputVid=VideoReader('VJ.mov');
mergedobj = VideoWriter('compositevid','Motion JPEG AVI');
mergedobj.FrameRate = inputVid.FrameRate; %match same framerate
mergedobj.Quality=100;
open(mergedobj);
%start the stitch
hfig = figure;
t = 0:(1/60):(162/60);
%while loop until there are no more frames
i = 1;
while hasFrame(inputVid)
%read in frame
singleFrame = readFrame(inputVid);
% display frame
subplot(3,2,[1 3 5]),imagesc(singleFrame), axis off, axis equal;
%my gen of dummy data or whatever you want to do
subplot(3,2,2);
plot(t(i),data.Position(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Position(1:i),'-k');
axis([0 t(end) 0 max(data.Position)+0.2])
subplot(3,2,4);
plot(t(i),data.Velocity(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Velocity(1:i),'-k');
axis([0 t(end) -3 3])
subplot(3,2,6);
plot(t(i),data.Accleration(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Accleration(1:i),'-k');
axis([0 t(end) -18 18])
pause(0.1)
if i ~= length(t)
clf
i= i+1;
else
close(mergedobj)
end
end
  1 comentario
Youngmin
Youngmin el 17 de Oct. de 2021
Thank you for your answer. The video was expanded on the left-hand side with the same height of three graphs. However, I still have the same warning and the video cannot be saved.
% Warning: No video frames were written to this file. The file may be invalid.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by