Create a movie from matrices

26 visualizaciones (últimos 30 días)
Luca Cattaneo
Luca Cattaneo el 24 de Mzo. de 2024
Comentada: DGM el 24 de Mzo. de 2024
Hi everyone, I need to create a movie from a series of 50x50 matrices. The real problem is not doing a movie, I succeded doing this using:
v = VideoWriter('peaks.mp4', 'MPEG-4');
open(v);
imagesc(matrix, clims);
frame = getframe;
writeVideo(v,frame);
But how can I save this file as a video? If I download it I can only save the last frame of the movie.
And how to reproduce it in MATLAB? It only shows the movie the first time (and also in a very fast way, but I cannot slow it) and I cannot see it from the beginning another time.
  2 comentarios
Stephen23
Stephen23 el 24 de Mzo. de 2024
Note that GETFRAME essentially captures a screenshot of the displayed axes/figure at the screen resolution. It does not save the image at its native resolution.
But given that you have the image data, you may want to save that (without even needing to display it).
DGM
DGM el 24 de Mzo. de 2024
For other ways of directly saving pseudocolor representations of arbitrarily-scaled 2D data without relying on screenshots, see:

Iniciar sesión para comentar.

Respuestas (1)

DGM
DGM el 24 de Mzo. de 2024
It only looks like you're capturing one frame, and you're not closing the writer object. There's an example in the documentation.
If you want to adapt that to using imagesc(), that's easy enough:
% some fake data
Z = peaks;
% set up the axes
imagesc(Z,[-10 10]);
axis tight manual
set(gca,"NextPlot","replacechildren")
% open the videowriter object
v = VideoWriter("peaks.avi");
open(v)
% capture all the animation frames
for k = 1:20
imagesc(sin(2*pi*k/20)*Z,[-10 10])
frame = getframe(gcf);
writeVideo(v,frame)
end
% close the writer
close(v);

Categorías

Más información sobre Animation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by