Displaying frames captured by getframe(h) at original size

18 次查看(过去 30 天)
I captured multiple frames from a figure, and would like to play them back one frame at a time. Please see the below example code:
h = figure;
for i=1:10
plot(rand(20, 1));
grid
title('Original figure');
xlabel('This is the original x label.');
MV(i) = getframe(h);
pause(0.01);
end
% The image displayed in this portion is *smaller* than the original plot,
% as it tries to fit the entire figure within the original axes
for i=1:10
image(MV(i).cdata);
% movie(h, MV(i));
pause;
end
The problem is, when displayed using "image(MV(i).cdata)", the entire content of the figure has to fit within the plotting axes, including title and labels, so there's a shrinkage. I could use "movie(h, MV(i))", which does not cause this rescaling, but "movie" has the bad habbit of clearing the figure each time, so the display is flashing annoyingly. Do you have better solutions? Thanks in advance!

采纳的回答

Chunru
Chunru 2021-10-7
You can use "imshow" which by default show images in 100% magnification. "doc imshow" for more details.
  3 个评论
Donald Liu
Donald Liu 2021-10-7
truesize did not seem to do what I intended, imshow is still displayed with ax2, and the whole figure is resized automatically:
h = figure;
ax1 = axes('Position', [0.49479 0.20139 0.41276 0.55556]);
ax2 = axes('Position', [0.13 0.52778 0.30359 0.39722]);
for i=1:10
axes(ax1);
plot(rand(20, 1));
grid
title(sprintf('Original figure %d', i));
xlabel('This is the original x label.');
axes(ax2);
plot(rand(100, 1));
MV(i) = getframe(h);
pause(0.01);
end
% Set up a new axes for use by imshow, rather than using the current axes
% axes('Position', [0 0 1 1]);
for i=1:10
imshow(MV(i).cdata, 'Border', 'tight');
truesize();
% image(MV(i).cdata);
pause(0.1);
end
For now I'll go with setting up a new axes('Position', [0 0 1 1]), as in my previous reply. Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by