Capture plot titles using getframe and writerobj
21 次查看(过去 30 天)
显示 更早的评论
I am recording the plots to make a movie. I am able to get the axis info on each frame but not able to get the title. Since with every interetion the title changes I want to capture that too. How can I do that?
0 个评论
采纳的回答
Turlough Hughes
2021-5-8
编辑:Turlough Hughes
2021-5-8
You can use the figure handle (instead of the axis handle) with the getframe function and that captures the entire interior of the figure window, including the axes title. Here's an example:
filename = 'testVideo.avi';
fontSize = 14;
% Initialisation
hf = figure(); % hf - figure handle
[X,Y,Z] = peaks(100);
hp = surf(X,Y,Z); % hp - plot handle
% Ensure axis limits are fixed
ax = gca;
axis([-4 4 -4 4 -10 10])
ax.ZLimMode = 'manual';
v = VideoWriter(filename); % v - video writer object
open(v)
% Example of a video scaling the peaks function
C = [0:0.1:20 19.9:-0.1:0]./20;
for ii = 1:numel(C)
% update the figure title
title(sprintf('Z = %.2fZ_P',C(ii)),'fontSize',fontSize)
% update the plot
hp.ZData = C(ii)*Z;
f = getframe(hf); % getframe using the fig. handle, hf.
writeVideo(v,f) % write video
end
close(v)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!