Output a video in MATLAB

10 visualizaciones (últimos 30 días)
Marios Christofides
Marios Christofides el 6 de Ag. de 2020
Comentada: Sudheer Bhimireddy el 7 de Ag. de 2020
I'm attempting to make a video of my plot in MATLAB and when I run it, the output plot is just blank and it doesn't show anything but the code still runs. Any feedback?
for t = 2:100001
time=(t-2)*dt;
f=a0*sin(time/(2*pi));
massspring(:,t) = VibrationPosition(massspring(:,t-1), time, a0, pi, m, k, c, f, dt, n);
drawnow
F(t) = getframe(gcf);
end
video = VideoWriter('Helix.avi','Uncompressed AVI');
open(video)
writeVideo(video,F);
close(video)
figure(1);
plot(t3, massspring(1,:), t3, massspring(2,:));
xlabel('Time (s)')
ylabel('x_1(t), x_2(t)')
title('Timestep 0.01')
title('Mass Position and Velocity over time')
legend('Mass Position','Mass Velocity')

Respuestas (1)

Sudheer Bhimireddy
Sudheer Bhimireddy el 6 de Ag. de 2020
Try this
video = VideoWriter('Helix.avi','Uncompressed AVI');
open(video);
h=figure(1);
hold on;
for t = 2:100001
% Do your stuff
plot();
F = getframe(gcf);
writeVideo(video,F);
end
% Once you have all the timesteps plotted then close the videwriter
close(video);
  4 comentarios
Marios Christofides
Marios Christofides el 7 de Ag. de 2020
I changed the directory but the original problem still persists except the axis are showing but nothing is being plotted.
Sudheer Bhimireddy
Sudheer Bhimireddy el 7 de Ag. de 2020
So, are you not getting the "permission denied" message anymore?
If you are able to see the axis and labels and title etc., then the problem might be with the data itself or you are restricting the axis limits so that the data is not in the visible window. Try setting
xlim([-inf inf]);
ylim([-inf inf]);
Also try with only one timestep and check. Also, check if your data has NaN values.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by