saving all open figures in script as .png file in a folder

75 Ansichten (letzte 30 Tage)
Ebrahim Karazama
Ebrahim Karazama am 29 Mär. 2022
Kommentiert: Voss am 31 Mär. 2022
working with image processing toolbox and trying to save all the figures as .png or .jpeg format in a specific folder using the code below:
FolderName = ('G:\Image proccessing\test'); % using my directory
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = num2str(get(FigHandle, 'Number'));
set(0, 'CurrentFigure', FigHandle);
saveas(FigHandle, strcat(FigName, '.png'));
end
there is no error but no image is saved.

Antworten (1)

Voss
Voss am 29 Mär. 2022
It may be that the .png files are being saved in the current working directory (because FolderName (G:\Image proccessing\test) is not being used).
Try this instead:
FolderName = ('G:\Image proccessing\test'); % using my directory
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = num2str(get(FigHandle, 'Number'));
set(0, 'CurrentFigure', FigHandle);
% saveas(FigHandle, strcat(FigName, '.png'));
saveas(FigHandle, fullfile(FolderName,strcat(FigName, '.png'))); % specify the full path
end
  2 Kommentare
Ebrahim Karazama
Ebrahim Karazama am 31 Mär. 2022
i realized that pictures was saved in current folder when i posted the question.
i try your suggestion but still the result is the same.
Voss
Voss am 31 Mär. 2022
Verify that FigList contains all your figures, and possibly use the debugging utilities to figure out where the code is going wrong.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by