save animation in subplot
18 views (last 30 days)
Show older comments
feynman feynman
on 15 Aug 2024
Commented: Walter Roberson
about 7 hours ago
I'm using
while
drawnow;hold off
end
to create an animation. But this animation is just the 6th position as in subplot(2,3,6) (or through next tile repeatedly). To save this animation to the computer while not keeping the other subplots 1~5, what to do?
2 Comments
Walter Roberson
on 16 Aug 2024
??
That is an infinite loop. Inside the infinite loop, you request that the graphics queue be flushed, and you turn off hold . But you do not do anything else -- no drawing at all, no recording of previously drawn material.
It is not clear what you are trying to do?
Accepted Answer
Walter Roberson
on 16 Aug 2024
ax6 = subplot(2,3,6);
count = 0;
while true
%draw something
count = count + 1;
filename = fullfile(SAVEDIRECTORY, "image" + count + ".png");
exportgraphics(ax6, filename);
end
7 Comments
Walter Roberson
about 6 hours ago
Unfortunately, getframe() results can end up being slightly different sizes. The exact size of axes depends upon the tick labels.
So you need something like
v = VideoWriter("file.avi");v.FrameRate=5;open(v);
first_frame = true;
while...
...
frame = getframe(gcf);
if first_frame
frame_size = size(frame.cdata);
remembered_size = frame_size(1:2);
first_frame = false;
else
frame.cdata = imresize(frame.cdata, remembered_size);
end
writeVideo(v,frame);
end
Walter Roberson
about 6 hours ago
subplot24=subplot(2,2,[2;4]);
%...
subplot2=subplot(2,2,2);
subplot24 is expected to be about twice the size of subplot2 . You will have trouble writing both of them to the same video, unless you imresize() to a common size.
More Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!