| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| R2010b Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
There are four basic operations that you can perform in printing or transferring figures you've created with MATLAB graphics to specific file formats for other applications to use.
Operation | Description |
|---|---|
Send a figure from the screen directly to the printer. | |
Write a figure to a PostScript® file to be printed later. | |
Export a figure in graphics format to a file, so that you can import it into an application. | |
Copy a figure to the Microsoft Windows clipboard, so that you can paste it into an application. |
In addition to typing MATLAB commands, you can use interactive tools for either Microsoft Windows or UNIX® to print and export graphics. The table below lists the GUIs available for doing this and explains how to open them from figure windows.
Dialog Box | How to Open | Description |
|---|---|---|
File > Print or printdlg function | Send figure to the printer, select the printer, print to file, and several other options | |
File > Print Preview or printpreview function | View and adjust the final output | |
File > Export | Export the figure in graphics format to a file | |
Edit > Copy Options | Set format, figure size, and background color for Copy to Clipboard | |
File > Preferences | Change text, line, axes, and UI control properties |
You can open the Print and Print Preview dialog boxes from a MATLAB file or from the command line with the printdlg and printpreview functions.
You can print a MATLAB figure from the command line or from a MATLAB file. Use the set function to set the properties that control how the printed figure looks. Use the print function to specify the output format and start the print or export operation.
Note Printed output from MATLAB commands and Print Previews of it are not guaranteed to duplicate the look of figures on your display screen in every detail. Many factors, including the complexity of the figure, available fonts, and whether a native printer driver or a MATLAB built-in driver to is used, affect the final output and can cause printed output to differ from what you see on your screen. |
The set function changes the values of properties that control the look of a figure and objects within it. These properties are stored with the figure; some are also properties of children such as axes or annotations. When you change one of the properties, the new value is saved with the figure and affects the look of the figure each time you print it until you change the setting again.
To change the print properties of the current figure, the set command has the form
set(gcf, 'Property1', value1, 'Property2', value2, ...)
where gcf is a function call that returns the handle of the current figure, and each property value pair consists of a named property followed by the value to which the property is set.
For example,
set(gcf, 'PaperUnits', 'centimeters', 'PaperType', 'A4', ...)
sets the units of measure and the paper size. Changing a Figure's Settings describes commonly used print properties. The Figure Properties reference page contains a complete list of the properties.
You can also use the get function to retrieve the value of a specific property.
a = get(gcf, 'Property')
Note
You can also peruse and modify figure and other object properties
with the Property Inspector GUI,
which you can open with the inspect command.
To open the current figure in the Property Inspector, type |
The print function performs any of the four actions shown in the table below. You control what action is taken, depending on the presence or absence of certain arguments.
Action | Print Command |
|---|---|
Print a figure to a printer | |
Print a figure to a file for later printing | print filename |
Copy a figure in graphics format to the clipboard on Microsoft Windows systems | print -dfileformat |
Export a figure to a graphics format file that you can later import into an application | print -dfileformat filename |
You can also include optional arguments with the print command. For example, to export Figure No. 2 to file spline2d.eps, with 600 dpi resolution, and using the EPS color graphics format, use
print -f2 -r600 -depsc spline2d
The functional form of this command is
print('-f2', '-r600', '-depsc', 'spline2d');
If you run with the PostScript -nodisplay startup option, or run without the DISPLAY environment variable set, you can use most print options that apply to the UNIX platform, but some restrictions apply. For example, in nodisplay mode uicontrols do not print; thus you cannot print a GUI if you run in this mode.
See Printing and Exporting without a Display in the documentation for the print function for details.
The table below lists parameters you can modify for the figure to be printed or exported. To change one of these parameters, use the Print Preview or the UNIX Print dialog box, or use the set or print function.
See Changing a Figure's Settings for more detailed instructions.
Parameter | Description |
|---|---|
Figure size | Set size of the figure on printed page |
Figure position | Set position of figure on printed page |
Paper size | Select printer paper, specified by dimension or type |
Paper orientation | Specify way figure is oriented on page |
Position mode | Specify figure position yourself or let it be determined automatically |
Graphics format | Select format for exported data (e.g., EPS, JPEG) |
Resolution | Specify how finely your figure is to be sampled |
Renderer | Select method (algorithm) for drawing graphics |
Renderer mode | Specify the renderer yourself or automatically determine which renderer to use based on the figure's contents |
Axes tick marks | Keep axes tick marks and limits as shown or automatically adjust them depending on figure size |
Background color | Keep background color as shown on screen or force it to white |
Line and text color | Keep line and text objects as shown on screen or print them in black and white |
UI controls | Show or hide all user interface controls in figure |
Bounding box | Leave space between outermost objects in plot and edges of its background area |
CMYK | Automatically convert RGB values to CMYK values |
Character set encoding | Select character set for PostScript printers |
If you have not changed the default print and export settings, MATLAB prints or exports the figure as follows:
8-by-6 inches with no window frame
Centered, in portrait format, on 8.5-by-11 inch paper if available
Using white background color for the figure and axes
Scaling ticks and limits of the axes to accommodate the printed size
In general, to change the property settings for a specific figure, follow the instructions given in the section Changing a Figure's Settings.
Any settings you change with the Print Preview and Print dialog boxes or with the set function are saved with the figure and affect each printing of the figure until you change the settings again.
The settings you change with the Figure Copy Template Preferences and Copy Options Preferences panels alter the figure as it is displayed on the screen.
You can set the session defaults for figure properties. Set the session default for a property using the syntax
set(0, 'DefaultFigurepropertyname', 'value')
where propertyname is one of the named figure properties. This example sets the paper orientation for all subsequent print operations in the current MATLAB session.
set(0, 'DefaultFigurePaperOrientation', 'landscape')
The Figure Properties reference page contains a complete list of the properties.
To see what default properties you can set that will be applied to all subsequent figures in the same MATLAB session, type
set(0,'default')
To see their current settings, type
get(0,'default')
You can set the session-to-session defaults for figure properties, the print driver, and the print function.
Print Device and Print Command. Set the default print driver and the default print command in your printopt.m file. This file contains instructions for changing these settings and for displaying the current defaults. Open printopt.m in your editor by typing the command
edit printopt
Scroll down about 40 lines until you come to this comment line:
%---> Put your own changes to the defaults here (if needed)
Add your changes after that line. For example, to change the default driver, first find the line that sets dev, and then replace the text string with an appropriate value. So, to set the default driver to HP LaserJet III, modify the line to read
dev = '-dljet3';
For the full list of values for dev, see the Drivers section of the print reference page.
Note If you set dev to be a graphics format, such as -djpeg, the figure is exported to that type of file rather than being printing. |
Figure Properties. Set the session-to-session default for a property by including commands like the following in your startup.m file:
set(0, 'DefaultFigurepropertyname', 'value')
where propertyname is one of the named figure properties. For example,
set(0, 'DefaultFigureInvertHardcopy', 'off')
keeps the figure background in the screen color.
This is the same command you use to change a session default, except by adding it to your startup.m file, it executes automatically every time you launch MATLAB.
Note Options you specify in arguments to the print command override properties set using MATLAB commands or the Print Preview dialog box, which in turn override any MATLAB default settings specified in printopt.m or startup.m. |
![]() | Printing and Exporting | How to Print or Export | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |