|On this page…|
Note To save a figure in a format that is compatible with MATLAB® versions prior to 7, refer to Plot Objects and Backward Compatibility for more information.
The MATLAB FIG-file is a binary format to which you can save figures so that they can be opened in subsequent MATLAB sessions. The whole figure, including graphs, graph data, annotations, data tips, menus and other uicontrols, is saved. (The only exception is highlighting created by data brushing.) These files have a .fig filename extension.
To save a graph in a figure file,
The graph is saved as a figure file (.fig), which is a binary file format used to store figures.
You can also use the saveas command.
Use the hgsave command to create backward compatible FIG-files.
If you want to save the figure in a format that can be used by another application, see Saving to a Different Format — Exporting Figures.
To open a figure file, perform these steps:
The figure file appears in a new figure window.
You can also use the open command.
To save a figure in a format that can be used by another application, such as the standard graphics file formats TIFF or EPS, perform these steps:
Select the graphic format from the list of formats in the Save as type drop-down menu. This selects the format of the exported file and adds the standard filename extension given to files of that type.
Note: Whenever you specify a format for saving a figure with the Save As menu item , that file format is used again the next time you save that figure or a new one. If you do not want to save in the previously-used format, use Save As and be sure to set the Save as type drop-down menu to the kind of file you want to write. However, saving a figure with the saveas function and a format does not change the Save as type setting in the GUI.
On Microsoft® systems, you can also copy a figure to the clipboard and then paste it into another application:
The figure is copied to the Windows® clipboard. You can then paste the figure from the Windows clipboard into a file in another application.
Before printing a figure,
The Print Preview dialog box opens.
On the Layout tab, click Auto (Actual Size, Centered).
On the Advanced tab, click Keep screen limits and ticks.
For information about other options for print preview, click the Help button in the dialog box.
To print a figure, select Print from the figure window File menu and complete the Print dialog box that appears.
You can also use the print command.
You can generate a MATLAB file from a graph, which you can then use to regenerate the graph. This approach is a useful way to generate MATLAB code for work you have performed with the plotting tools. To use this option,
The generated code displays in the MATLAB Editor.
Most of the generated files require you to pass in data as arguments. The file assumes you are using the same data originally used to create the graph.
Comments at the beginning of the file state the type of data expected. For example, the following statements illustrate a case where three input vectors are required.
function createplot(X1, Y1, Y2) %CREATEPLOT(X1,Y1,Y2) % X1: vector of x data % Y1: vector of y data % Y2: vector of y data
See Generating MATLAB Code to Reproduce a Graph for another example.