Saving resized figures in loop does all but last correctly

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일

0 개 추천

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

댓글 수: 1

Thanks for your suggestion. Still having the same issue, unfortunately.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

AES
2023년 10월 30일

편집:

AES
2023년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by