Save Axes Without Saving UIControls
To save only the axes from a figure that has uicontrols, you can useprint
with the'-noui'
option. Alternatively, you can copy the axes to a new figure and save the new figure.
Create Figure with UIControls
To create an example of a figure with uicontrols, set your current folder to one to which you have write access. Then, copy this example code.
copyfile(fullfile(docroot,'techdoc','creating_guis','examples','simple_gui2*.*')); simple_gui2
Save Axes Without Saving UIControls
To save the figure and exclude the uicontrols from the saved output, useprint
with the'-noui'
option.print
leaves blank space in place of the uicontrols. If you do not specify the'-noui'
option, thenprint
includes the uicontrols in the saved output.
To maintain the current figure background color in the saved figure, set theInvertHardcopy
property of the figure to'off'
. Otherwise, the saved figure has a white background. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use theset
function instead.
fig = gcf; fig.InvertHardcopy ='off'; print('PlotWithoutUIControls','-dpng','-noui')
Copy Axes to New Figure and Save
To eliminate the blank space, copy the axes to a new figure and resize the axes to fill the figure. For example, click the axes to make it the current axes. Usecopyobj
to copy it to a new figure. Then, set thePosition
property of the new axes to fill the figure.
ax_old = gca; f_new = figure; ax_new = copyobj(ax_old,f_new) set(ax_new,'Position','default')
Save the new figure using eithersaveas
orprint
.
print(f_new,'AxesOnly','-dpng')