How to save animated plots

Hi
I have an animated plot, and I want to save it - possibly an animation, and I want to know how to do it?

 Respuesta aceptada

Clay Swackhamer
Clay Swackhamer el 11 de Abr. de 2019

18 votos

%% Make some data
t = 1:0.1:2*pi
y = sin(t)
%% Initialize video
myVideo = VideoWriter('myVideoFile'); %open video file
myVideo.FrameRate = 10; %can adjust this, 5 - 10 works well for me
open(myVideo)
%% Plot in a loop and grab frames
for i=1:1:length(t)
plot(t(1:i), y(1:i), 'LineWidth', 3)
ylim([-1, 1])
xlim([0, 2*pi])
pause(0.01) %Pause and grab frame
frame = getframe(gcf); %get frame
writeVideo(myVideo, frame);
end
close(myVideo)

5 comentarios

Prakhar Sharma
Prakhar Sharma el 12 de Mzo. de 2020
Its, perfect. is there any way to improve the quality of the video.
Moein M
Moein M el 10 de Jun. de 2020
Is there a way to control the speed at which the plot is being drawn? @Swackhamer
It would be great if you add that to the code.
Clay Swackhamer
Clay Swackhamer el 10 de Jun. de 2020
You could try adding
pause(0.25) %pause 0.25 seconds
in the loop to slow it down. It could also work to play with the framerate parameter.
Hope that helps.
Clay
Emma Visibelli
Emma Visibelli el 22 de Dic. de 2020
Hi everyone!
Can I ask you a favour as it may be similar to the previous one?
I am trying to copy/transfer a plot (figure) in psychtool box window.
Do you know how I can do that?
I have my plot:
AccuracyFinal=[accuracy1,accuracy2,accuracy3,accuracy4,accuracy5];
plot(AccuracyFinal,'b--','LineWidth',5);
title('The Test Trend')
xlabel('Exercise')
ylabel('Accuracy')
legend('Trend','Location','northeast')
xlim ([1 5])
xticks([1 2 3 4 5])
ylim ([0 100])
yticks([10 20 30 40 50 60 70 80 90 100])
This is how I transfered it to psychtool box window with this code:
set(gcf, 'Position', [0 0 250 250]);
saveas(gcf, 'img.jpg');
myImage=imread("img.jpg");
tex=Screen('MakeTexture',win, myImage);
Screen('DrawTexture', win,tex)
The problem is that the name of axes do not appear and neither the title or the legend!
Please let me knwo if you can help me out!!
Thank you!
Clay Swackhamer
Clay Swackhamer el 22 de Dic. de 2020
I'm not sure why, but could you simply re-add the axes titles, title, and such once you replot it?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Animation en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 11 de Abr. de 2019

Comentada:

el 22 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by