Documentation

Save Axes Without Saving UIControls

To save only the axes from a figure that has uicontrols, you can useprintwith 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, useprintwith the'-noui'option.printleaves blank space in place of the uicontrols. If you do not specify the'-noui'option, thenprintincludes the uicontrols in the saved output.

To maintain the current figure background color in the saved figure, set theInvertHardcopyproperty 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 thesetfunction 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. Usecopyobjto copy it to a new figure. Then, set thePositionproperty 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 eithersaveasorprint.

print(f_new,'AxesOnly','-dpng')

See Also

|

Related Topics

Was this topic helpful?