|On this page…|
figure bar(randn(1,5),'BarWidth',0.5); savefig barGraph
You can reload the graph using openfig:
fig = openfig('barGraph');
MATLAB® creates a new figure, a new axes, and a new bar object using the same data as the original objects. Most of the property values of the new objects are the same as the original objects.
However, the Parent and Children properties now contain the new object handles. Also, MATLAB applies any default or system values that are different from those in the environment in which you saved the figure.
For example, suppose you set a default figure color after saving the barGraph.fig file. MATLAB uses the default when creating the new figure.
To get the handle to the new bar object, use findobj and the figure handle returned by openfig:
h = findobj(fig,'Type','bar');
You can use h2 to set and get properties on the new bar object:
ans = 0.5000
For more information on finding objects, see Find Objects
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.
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 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 savefig command to create backward compatible FIG-files.
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.
You can use the Save As dialog to export a figure to a standard file format:
Select Save As from the File menu.
Enter a file name in the File name text field
Select a file type from the Save as type drop-down menu.
You can also use the saveas function to export figure to specific file formats. However, the saveas function and the Save As dialog do not produce identical results:
The Save As dialog produces images at screen resolution and at screen size.
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 reproduce the graph. This feature is particularly useful for capturing modifications you make using the plot tools.
The generated code displays in the MATLAB Editor.
Generated files do not store the data necessary to recreate the graph, so you must supply the data arguments. The data arguments do not need to be identical to the original data. 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 createfigure(yvector1) %CREATEFIGURE(YVECTOR1) % YVECTOR1: bar yvector % Auto-generated by MATLAB on 08-Jul-2014 17:19:46 % Create figure figure1 = figure; % Create axes axes1 = axes('Parent',figure1,'XTick',[1 2 3 4 5]); box(axes1,'on'); hold(axes1,'on'); % Create bar bar(yvector1,'BarWidth',0.5);