Save an image with a different name using GUI

1 view (last 30 days)
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'.

Answers (1)

Brian Neiswander
Brian Neiswander on 13 Aug 2015
The function "savefig" was introduced in MATLAB R2013b. If you are using a version earlier than MATLAB R2013b, try using:
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:
where &ltmatlabroot&gt is the output of the command:
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".

Community Treasure Hunt

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

Start Hunting!

Translated by