Capture plot titles using getframe and writerobj

조회 수: 25 (최근 30일)
Yash Phirke
Yash Phirke 2021년 5월 8일
편집: Turlough Hughes 2021년 5월 8일
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?

채택된 답변

Turlough Hughes
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개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by