Main Content


Export contents of figure




    exportgraphics and copygraphics are recommended over hgexport because they enable you to capture the contents of a figure or an axes object. Both functions have several options for customizing the output and specifying whether to capture vector graphics or an image. (since R2020a)

    For more information about the different ways to export graphics, see Compare Ways to Export Graphics from Figures.

    hgexport(fig,filename) exports the contents of the figure fig to an EPS file with the specified file name.

    hgexport(fig,"-clipboard") copies the contents of the figure to the clipboard. This syntax is supported on Windows® systems only.

    The content is copied either as vector graphics or as an image, depending on the renderer. If the renderer is Painters, then the content is copied as a Windows metafile. If the renderer is OpenGL®, then the content is copied as an image. Use the rendererinfo function to determine the renderer. Changing the renderer will not be possible in a future release.


    collapse all

    Create a plot and get the current figure by calling the gcf function.

    plot([0 0.3 0.1 0.6 0.4 1])
    fig = gcf;

    Line plot

    Save the contents of the figure to the file myplot.eps


    Input Arguments

    collapse all

    Figure to export, specified as a figure object.

    File name, specified as a string scalar or a character vector.

    Example: hgexport(gcf,"myfile.eps") specifies a string scalar for the file name.

    Example: hgexport(gcf,'myfile.eps') specifies a character vector for the file name.

    Version History

    Introduced before R2006a

    expand all