Save .fig and .jpg to folders selected earlier

1 回表示 (過去 30 日間)
Tyler
Tyler 2022 年 12 月 2 日
回答済み: Hiro Yoshino 2022 年 12 月 2 日
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");

回答 (1 件)

Hiro Yoshino
Hiro Yoshino 2022 年 12 月 2 日
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.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by