Capture plot titles using getframe and writerobj

27 Ansichten (letzte 30 Tage)
Yash Phirke
Yash Phirke am 8 Mai 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?

Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 8 Mai 2021
Bearbeitet: Turlough Hughes am 8 Mai 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)

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by