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

 Akzeptierte Antwort

Matt J
Matt J am 30 Okt. 2023

0 Stimmen

Maybe use export_fig or exportgraphics, instead of saveas.

1 Kommentar

AES
AES am 30 Okt. 2023
Bearbeitet: AES am 30 Okt. 2023
Thank you this solved the issue. For reference I ended up using exportgraphics*

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 30 Okt. 2023
Bearbeitet: Matt J am 30 Okt. 2023
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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

AES
am 30 Okt. 2023

Bearbeitet:

AES
am 30 Okt. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by