Save .fig and .jpg to folders selected earlier

1 view (last 30 days)
Tyler
Tyler on 2 Dec 2022
Answered: Hiro Yoshino on 2 Dec 2022
How do I use the full file name from a uigetdir() source earlier in the code to save a plot as both a JPG and FIG file type?
%This is at the start of the code and it updates a text box field with the full file path of the folder in which I
%want the correct plot files to be saved to
properties (Access = private)
JPEGSaveLocation
MATLABFigureSaveLocation
end
% Callbacks that handle component events
methods (Access = private)
% Callback function: JPEGSaveLocationButton,
% JPEGSaveLocationEditField
function JPEGSaveLocationButtonPushed(app, event)
app.JPEGSaveLocation = uigetdir('*', 'Select Folder to save JPEG');
app.JPEGSaveLocationEditField.Value = app.JPEGSaveLocation;
end
% Callback function: MatLabFigureSaveLocationButton,
% MatLabFigureSaveLocationEditField
function MatLabFigureSaveLocationButtonPushed(app, event)
app.MATLABFigureSaveLocation = uigetdir('*', 'Select Folder to save MATLAB Figures');
app.MatLabFigureSaveLocationEditField.Value = app.MATLABFigureSaveLocation;
%This is at the end of the code and it currently saves both file types to
%the folder where the data comes from. I want them to save to the selected
%folders using the paths from above
savefig(ParentFolderPath);
exportgraphics(gca,ParentFolderPath + ".jpg");

Answers (1)

Hiro Yoshino
Hiro Yoshino on 2 Dec 2022
I would add some more code in the MatlabFigureSaveLocationButtonPushed function as follows:
saveFileName = "myFileName";
savefig(fullfile(app.MATLABFigureSaveLocation,saveFileName)); % for fig
exportgraphics(gca,app.MATLABFigureSaveLocation,saveFileName + ".jpg"); % for JPEG
see how fullfile works for you.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!