MATLAB: How to delete a plot that I saved in the GUI figure

figureguiMATLABsave

When developing a GUI using GUIDE, I clicked on the save button on the GUI figure toolbar. As a consequence the plot that I had loaded into the GUI at that time got permanently saved. That plot now gets loaded into the GUI figure whenever I run my GUI.
I do not see this information saved in the handles structure used by the GUI code.
I would like to know how I can delete the plot saved in the GUI figure.

Best Answer

In the event you have stored the result of running a PLOT command in the GUI FIG-file, please execute the following code to clear the axes in your GUI:
1. Run your GUI.
2. At the Command Window type the following:
set(0,'ShowHiddenHandles','on');
cla; %clears the current axes
hgsave('mygui.fig');
set(0,'ShowHiddenHandles','off');
The issue of the plot being saved in the axes of the GUI is not due to information saved in the handles structure. When you save a GUIDE FIG-file during operation of the GUI, data reflecting the current state of the GUI is stored in the FIG-file. This data is not visible in the corresponding code file and therefore it cannot be deleted by manipulating the handles structure.
The figure toolbar and menubar are not present in a GUI created in GUIDE by default since saving data while the GUI is open will cause data to be saved in the .FIG file. This information is not accessible from the code file. Hence it is recommended not to have the save button and in general the menubar in a GUI.
Related Question