Save .fig and .jpg to folders selected earlier
조회 수: 1 (최근 30일)
이전 댓글 표시
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");
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!