How to save animated plots
351 views (last 30 days)
Show older comments
Hans123
on 11 Apr 2019
Commented: Clay Swackhamer
on 22 Dec 2020
Hi
I have an animated plot, and I want to save it - possibly an animation, and I want to know how to do it?
0 Comments
Accepted Answer
Clay Swackhamer
on 11 Apr 2019
%% 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 Comments
Clay Swackhamer
on 22 Dec 2020
I'm not sure why, but could you simply re-add the axes titles, title, and such once you replot it?
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!