Capture plot titles using getframe and writerobj

27 visualizaciones (últimos 30 días)
Yash Phirke
Yash Phirke el 8 de Mayo de 2021
Editada: Turlough Hughes el 8 de Mayo de 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?

Respuesta aceptada

Turlough Hughes
Turlough Hughes el 8 de Mayo de 2021
Editada: Turlough Hughes el 8 de Mayo de 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)

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by