Saving image in full screen with TiledLayout

32 次查看(过去 30 天)
With reference to this post: Saving a figure in full screen size? - MATLAB Answers - MATLAB Central (mathworks.com), I want to save a figure using the save function by forcing it to size it to my screen. This works with the post mentioned when using figure, but when using tiledLayout as:
t=tiledlayout(1,2,'Position',get(0,'Screensize'));
% plot goes here%
F = getframe(t);
saveas(F.data,'my_plot.jpg','jpg');
I get the following error:
Error using getframe (line 2)
A valid figure or axes handle must be specified
Error in plot_test (line
3)
F = getframe(t);

回答(1 个)

Dave B
Dave B 2021-8-27
Could you set the figure position to be fullscreen, and keep the tiledlayout at the default (which occupies the full figure window)?
fig = figure('Position', get(0, 'Screensize'));
t=tiledlayout(1,2);
% plot goes here%
F = getframe(fig);
imwrite(F.cdata, 'my_plot.jpg', 'jpg')
  1 个评论
Dave B
Dave B 2021-8-27
编辑:Dave B 2021-8-27
(note that if you set tiledlayout's 'Padding' property to 'none' there won't be a border between the layout and the figure)
figure
set(gcf,'Color',[.8 .8 .8])
t=tiledlayout(2,2);
for i = 1:4;nexttile;end
figure
set(gcf,'Color',[.8 .8 .8])
t=tiledlayout(2,2,'Padding','none');
for i = 1:4;nexttile;end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by