Save appdesigner windows automatically in user specified folder

1 view (last 30 days)
Hi ,
I am developing an tool in appdesigner, in which when I select and run one model, new window will open up asking the inputs and if I press continue in that window, one more new window will open up with the respective graphs.
Like that, I have multiple windows will open up based on whether I will continue or exit (using button).
At the end of the program, I need to save all the windows opened into a folder specified by the user,
Please help me with this
In the run button I am writing the code like this
RunLwrExtModeCal; %The .m file which needs to run
% FolderName = images; % Your destination folder
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = get(FigHandle, 'Name');
folder = "E:\TATA ELXSI\Calibration_App\images"
fullFileName = fullfile(folder,FigName,'.fig');
savefig(FigHandle, fullfile(folder, FigName, '.fig'));
end

Answers (1)

Vedant Shah
Vedant Shah on 30 May 2025
To ensure that all open figure windows are saved correctly while running an application in App Designer, we can prompt the user to select a destination folder before executing the save operation. This can be achieved by incorporating the following lines of code before the code mentioned in the question:
folder = uigetdir(pwd, 'Select Folder to Save Figures');
if folder == 0
return;
end
This will ensure that the user explicitly selects a valid directory. If the selection is cancelled, the operation will be terminated.
Additionally, the original lines:
folder = "E:\TATA ELXSI\Calibration_App\images"
fullFileName = fullfile(folder,FigName,'.fig');
should be replaced with the following:
if isempty(FigName)
FigName = ['Figure_' num2str(iFig)];
end
This modification eliminates the need for hardcoded paths by using the user-defined folder paths and ensures consistent figure naming by assigning a default name using a standard pattern when none is provided.
Furthermore, the original use of:
savefig(FigHandle, fullfile(folder, FigName, '.fig'));
would create a subfolder named after the figure, rather than saving a .fig file. Replacing it with:
savefig(FigHandle, fullfile(folder, [FigName, '.fig']));
ensures that the figure is saved as a file within the specified directory.
For more information, please refer to the following documentation:

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!