Saving resized figures in loop does all but last correctly

1 次查看(过去 30 天)
I am trying to save all my figures after resizing them to fit my entire screen. I use a loop to go through the figures, however, while the last figure is resized correctly it is not saved as a png at the correct size. This is true no matter the order I save the figures. Any tips on how to solve this? Below is a small snippet of code:
h = findall(groot, 'Type', 'figure');
for numFig = 1:length(h)
figure(numFig)
set(numFig, 'Position', get(0, 'Screensize'));
saveas(h(numFig), [tempLoc, h(numFig).Name, '.png'])
end

采纳的回答

Matt J
Matt J 2023-10-30
Maybe use export_fig or exportgraphics, instead of saveas.
  1 个评论
AES
AES 2023-10-30
编辑:AES 2023-10-30
Thank you this solved the issue. For reference I ended up using exportgraphics*

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2023-10-30
编辑:Matt J 2023-10-30
Maybe issue a call to drawnow?
h = findall(groot, 'Type', 'figure');
for numFig = 1:length(h)
figure(numFig)
set(numFig, 'Position', get(0, 'Screensize')); drawnow
saveas(h(numFig), [tempLoc, h(numFig).Name, '.png'])
end

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by