MATLAB: How to copy the axes from an existing GUI into a new figure so that the new figure does not have any uicontrols

MATLABnouicontrols

I have a GUI containing a plot and some uicontrols. I would like to create a new figure containing only the plot without any of the uicontrols.

Best Answer

There are two ways of accomplishing this. The basic idea is to copy the axes containing the desired plot into a new figure.
Graphically:
1. With the GUI window open and current, enter the following command at the MATLAB Prompt.
set(gcf,'menubar','figure')
This will bring up the menubar at the top of the GUI Window.
2. Select ‘View -> Plot Browser’ in the menubar. This will bring up the plot browser on the right of the figure window.
3. Select the desired axes within the Plot Browser by clicking on it.
4. Select Edit -> Copy in the menubar.
5. Open up a new figure window by typing
figure
at the MATLAB command prompt.
6. In the new figure window menubar, select ‘View -> Plot Browser’
7. Select ‘Edit -> Paste’ in the new figure window menubar. This will cause the axes to get copied to the new figure.
The command line equivalent of the above operation is listed below. Run the following code with the GUI figure window open and current.
set(0,'showhiddenhandles','on') % Make the GUI figure handle visible
h = findobj(gcf,'type','axes') % Find the axes object in the GUI
f1 = figure % Open a new figure with handle f1
s = copyobj(h,f1) % Copy axes object h into figure f1