10.14: Saving and Opening Figures

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    10.14: Saving and Opening Figures

    Sometimes you may want to save a MATLAB figure so that you can reopen and edit it later. MATLAB figure files use the .fig extension.

    Example \(\PageIndex{1}\)

    Saving a plot and opening an existing plot.

    clear; clc; clf;
    
    x = linspace(1, 10, 30);
    y = x.^2;
    
    plot(x, y, 'md')
    title('y = x^2')
    xlabel('x')
    ylabel('y')
    grid on
    
    % Save the current figure
    savefig('myplot.fig')
    
    % Close all open figure windows
    close all
    
    % Reopen the saved figure
    openfig('myplot.fig')
    
    Solution

    After running the code in MATLAB, notice that a new file called myplot.fig appears in the current working directory.

    The generated plot:

    clipboard_ebc875b98ab27fece32990a5e01f76fc8.png

    A .fig file is useful when you want to reopen the figure in MATLAB and continue editing it. If you want to include a plot in a report, you may also export it as an image file, such as PNG, or copy it directly into your document.


    This page titled 10.14: Saving and Opening Figures was last modified on Tue, 30 Jun 2026 02:11:47 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.