Save an image with a different name using GUI

조회 수: 1 (최근 30일)
Christophe Nell
Christophe Nell 2015년 8월 11일
답변: Brian Neiswander 2015년 8월 13일
hello, I've created using GUIDE a function that allow me do make a graph and modify parameters. I add the button "Save Figure" from the Toolbar Layout but it saves it with the same name than the original figure using by GUI.
I wanted to have a different name using a callback function linked to the save button. However, with the function savefig ('newname.fig') I have the error: Undefined function 'savefig' for input arguments of type 'char'.

답변 (1개)

Brian Neiswander
Brian Neiswander 2015년 8월 13일
The function "savefig" was introduced in MATLAB R2013b. If you are using a version earlier than MATLAB R2013b, try using:
saveas(gcf,'newname.fig');
If you are using MATLAB R2013b or later, check if there is a local function named "savefig" that is causing this error. You can do this by executing:
which -all savefig
The output should show something similar to:
<matlabroot>\toolbox\matlab\graphics\savefig.p
where &ltmatlabroot&gt is the output of the command:
matlabroot
If the output is not located inside your &ltmatlabroot&gt directory, then there is a local function named "savefig" in your path that is interfering with the MATLAB function. You can rename the local "savefig.m" file and function to a different name and try executing your application again.
If the suggestions above do not solve the issue, then try regenerating the callback function. In the "Toolbar Editor" window click on the "View" button to right of "Clicked Callback". You may get a popup dialog asking if you want to replace the current value of the callback with a GUIDE auto-generated callback. If so, click "Yes".
An M-file with an auto-generated callback function will open inside the MATLAB Editor window. Inside this callback function, put the code:
savefig ('newname.fig');
You can now try executing the application again and the "Save" button in the toolbar should generate the file "newname.fig".

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by