Capture plot titles using getframe and writerobj
12 views (last 30 days)
Show older comments
Yash Phirke
on 8 May 2021
Edited: Turlough Hughes
on 8 May 2021
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 Comments
Accepted Answer
Turlough Hughes
on 8 May 2021
Edited: Turlough Hughes
on 8 May 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Annotations 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!