| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
Select File > Print from the figure window to open the Print dialog box and File > Print Preview to open the Print Preview GUI. For details, see "How to Print or Export" in the MATLAB Graphics documentation.
print
print filename
print -ddriver
print -dformat
print -dformat filename
print -smodelname
print -options
print(...)
[pcmd,dev] = printopt
print and printopt produce hard-copy output. All arguments to the print command are optional. You can use them in any combination or order.
print sends the contents of the current figure, including bitmap representations of any user interface controls, to the printer using the device and system printing command defined by printopt.
print filename directs the output to the PostScript file designated by filename. If filename does not include an extension, print appends an appropriate extension.
print -ddriver prints the figure using the specified printer driver, (such as color PostScript). If you omit -ddriver, print uses the default value stored in printopt.m. The table in Printer Drivers lists all supported device types.
print -dformat copies the figure to the system Clipboard (Microsoft Windows platforms only). To be valid, the format for this operation must be either -dmeta (Windows Enhanced Metafile) or -dbitmap (Windows Bitmap).
print -dformat filename exports the figure to the specified file using the specified graphics format (such as TIFF). The table of Graphics Format Files lists all supported graphics file formats.
print -smodelname prints the current Simulink model modelname.
print -options specifies print options that modify the action of the print command. (For example, the -noui option suppresses printing of user interface controls.) Printing Options lists available options.
print(...) is the function form of print. It enables you to pass variables for any input arguments. This form is useful for passing file names and handles. See Batch Processing for an example. Also see Specifying the Figure to Print for further examples.
[pcmd,dev] = printopt returns strings containing the current system-dependent printing command and output device. printopt is an M-file used by print to produce the hard-copy output. You can edit the M-file printopt.m to set your default printer type and destination.
pcmd and dev are platform-dependent strings. pcmd contains the command that print uses to send a file to the printer. dev contains the printer driver or graphics format option for the print command. Their defaults are platform dependent.
Platform | Print Command | Driver or Format |
|---|---|---|
Mac and UNIX | ||
Windows |
The following table shows the more widely used printer drivers supported by MATLAB software. If you do not specify a driver, the default setting shown in the previous table is used. For a list of all supported printer drivers, type print -d at the MATLAB prompt. Some things to remember:
As indicated in Description the -d switch specifies a printer driver or a graphics file format:
Specifying a printer driver without a file name or printer name (the -P option) sends the output formatted by the specified driver to your default printer, which may not be what you want to do.
Specifying a -dmeta or a -dbitmap graphics format without a file name places the graphic on the system Clipboard, if possible (Windows platforms only).
Specifying any other graphics format without a file name creates a file in the current folder with a name such as figureN.fmt, where N is 1, 2, 3, ... and fmt indicates the format type, for example, eps or png.
Several drivers come from a product called Ghostscript, which is shipped with MATLAB software. The last column indicates when Ghostscript is used.
Not all drivers are supported on all platforms. Non support is noted in the first column of the table.
If you specify a particular printer with the -P option and do not specify a driver, a default driver for that printer is selected, either by the operating system or by MATLAB , depending on the platform:
On MATLAB, the driver associated with this particular printing device is used.
On Macintosh and UNIX platforms, the driver specified in printop.m is used
See Selecting the Printer in the Graphics documentation for more information.
Note The MathWorks™ is planning to leverage existing operating system (OS) support for printer drivers and devices. As a result, the ability to specify certain print devices using the print -d command, and certain graphics formats using the print -d command and/or the saveas command, will be removed in a future release. In the following table, the affected formats have an asterisk (*) next to the print command option string. The asterisks provide a link to the Web site which supplies a form for users to give feedback about these changes. |
Printer Driver | Print Command Option String | Ghostscript |
|---|---|---|
Canon BubbleJet BJ10e | -dbj10e * | Yes |
Canon BubbleJet BJ200 color | -dbj200 * | Yes |
Canon Color BubbleJet BJC-70/BJC-600/BJC-4000 | -dbjc600 * | Yes |
Canon Color BubbleJet BJC-800 | -dbjc800 * | Yes |
Epson and compatible 9- or 24-pin dot matrix print drivers | -depson * | Yes |
Epson and compatible 9-pin with interleaved lines (triple resolution) | -deps9high * | Yes |
Epson LQ-2550 and compatible; color (not supported on HP-700) | -depsonc * | Yes |
Fujitsu 3400/2400/1200 | -depsonc * | Yes |
HP DesignJet 650C color (not supported on Windows ) | -ddnj650c * | Yes |
HP DeskJet 500 | -ddjet500 * | Yes |
HP DeskJet 500C (creates black and white output) | -dcdjmono * | Yes |
HP DeskJet 500C (with 24 bit/pixel color and high-quality Floyd-Steinberg color dithering) (not supported on Windows ) | -dcdjcolor * | Yes |
HP DeskJet 500C/540C color (not supported on Windows ) | -dcdj500 * | Yes |
HP Deskjet 550C color (not supported on Windows ) | -dcdj550 * | Yes |
HP DeskJet and DeskJet Plus | -ddeskjet * | Yes |
HP LaserJet | -dlaserjet * | Yes |
HP LaserJet+ | -dljetplus * | Yes |
HP LaserJet IIP | -dljet2p * | Yes |
HP LaserJet III | -dljet3 * | Yes |
HP LaserJet 4, 5L and 5P | -dljet4 * | Yes |
HP LaserJet 5 and 6 | -dpxlmono * | Yes |
HP PaintJet color | -dpaintjet * | Yes |
HP PaintJet XL color | -dpjxl * | Yes |
HP PaintJet XL color | -dpjetxl * | Yes |
HP PaintJet XL300 color (not supported on Windows ) | -dpjxl300 * | Yes |
HPGL for HP 7475A and other compatible plotters. (Renderer cannot be set to Z-buffer.) | -dhpgl * | No |
IBM 9-pin Proprinter | -dibmpro * | Yes |
PostScript black and white | No | |
PostScript color | No | |
PostScript Level 2 black and white | No | |
PostScript Level 2 color | No | |
Windows color (Windows only) | No | |
Windows monochrome (Windows only) | No |
To save your figure as a graphics format file, specify a format switch and file name. To set the resolution of the output file for a built-in MATLAB format, use the -r switch. (For example, -r300 sets the output resolution to 300 dots per inch.) The -r switch is also supported for Windows Enhanced Metafiles, JPEG, TIFF and PNG files, but is not supported for Ghostscript raster formats. For more information, see Printing and Exporting without a Display and Resolution Considerations.
Note When you print to a file, the file name must have fewer than 128 characters, including path name. When you print to a file in your current folder, the filename must have fewer than 126 characters, because MATLAB places './' or '.\'' at the beginning of the filename when referring to it. |
The following table shows the supported output formats for exporting from figures and the switch settings to use. In some cases, a format is available both as a MATLAB output filter and as a Ghostscript output filter. All formats except for EMF are supported on both PC and UNIX platforms.
Bitmap or Vector | Print Command Option String | MATLAB or Ghostscript | |
|---|---|---|---|
BMP monochrome BMP | Bitmap | Ghostscript | |
BMP 24-bit BMP | Bitmap | Ghostscript | |
BMP 8-bit (256-color) BMP (this format uses a fixed colormap) | Bitmap | Ghostscript | |
BMP 24-bit | Bitmap | MATLAB | |
EMF | Vector | MATLAB | |
EPS black and white | Vector | MATLAB | |
EPS color | Vector | MATLAB | |
EPS Level 2 black and white | Vector | MATLAB | |
EPS Level 2 color | Vector | MATLAB | |
HDF 24-bit | Bitmap | MATLAB | |
ILL (Adobe Illustrator) | Vector | MATLAB | |
JPEG 24-bit | Bitmap | MATLAB | |
PBM (plain format) 1-bit | Bitmap | Ghostscript | |
PBM (raw format) 1-bit | Bitmap | Ghostscript | |
PCX 1-bit | Bitmap | Ghostscript | |
PCX 24-bit color PCX file format, three 8-bit planes | Bitmap | Ghostscript | |
PCX 8-bit newer color PCX file format (256-color) | Bitmap | Ghostscript | |
PCX Older color PCX file format (EGA/VGA, 16-color) | Bitmap | Ghostscript | |
PDF Color PDF file format | Vector | Ghostscript | |
PGM Portable Graymap (plain format) | Bitmap | Ghostscript | |
PGM Portable Graymap (raw format) | Bitmap | Ghostscript | |
PNG 24-bit | Bitmap | MATLAB | |
PPM Portable Pixmap (plain format) | Bitmap | Ghostscript | |
PPM Portable Pixmap (raw format) | Bitmap | Ghostscript | |
TIFF 24-bit | Bitmap | MATLAB | |
TIFF preview for EPS files | Bitmap |
The TIFF image format is supported on all platforms by almost all word processors for importing images. The -dtiffn variant writes an uncompressed TIFF. JPEG is a lossy, highly compressed format that is supported on all platforms for image processing and for inclusion into HTML documents on the Web. To create these formats, MATLAB renders the figure using the Z-buffer rendering method and the resulting bitmap is then saved to the specified file.
On a UNIX platform (including Macintosh), where you can start in MATLAB nodisplay mode (matlab -nodisplay), you can print using most of the drivers you can use with a display and export to most of the same file formats. The PostScript and Ghostscript devices all function in nodisplay mode on UNIX platforms. The graphic devices -djpeg, -dpng, -dtiff (compressed TIFF bitmaps), and -tiff (EPS with TIFF preview) work as well, but under nodisplay they use Ghostscript to generate output instead of using the drivers built into MATLAB. However, Ghostscript ignores the -r option when generating -djpeg, -dpng, -dtiff, and -tiff image files. This means that you cannot vary the resolution of image files when running in nodisplay mode.
Naturally, the Windows only -dwin and -dwinc output formats cannot be used on UNIX or Mac platforms with or without a display.
The same holds true on Windows platforms with the -noFigureWindows startup option. The -dwin, -dwinc, and -dsetup options operate as usual under -noFigureWindows. However, the printpreview GUI does not function in this mode.
The formats which you cannot generate in nodisplay mode on UNIX and Mac platforms are:
bitmap (-dbitmap) — Windows bitmap file (except for Simulink models)
bmp (-dbmp...) — Monochrome and color bitmaps
hdf (-dhdf) — Hierarchical Data Format
svg (-dsvg) — Scalable Vector Graphics file (except for Simulink models)
tiffn (-dtiffn) — TIFF image file, no compression
In addition, uicontrols do not print or export in nodisplay mode.
This table summarizes options that you can specify for print. The second column links to tutorials in Printing and Exporting in the MATLAB Graphics documentation that provide operational details. Also see Resolution Considerations for information on controlling output resolution.
Option | Description |
|---|---|
PostScript devices only. Use PostScript default character set encoding. See "Early PostScript 1 Printers". | |
PostScript devices only. Append figure to existing PostScript file. See "Settings That Are Driver Specific". | |
PostScript devices only. Print with CMYK colors instead of RGB. See "Setting CMYK Color". | |
Printing only. Printer driver to use. See Printer Drivers table. | |
Exporting only. Graphics format to use. See "Graphics Format Files" table. | |
Windows printing only. Display the (platform-specific) Print Setup dialog. Settings you make in it are saved, but nothing is printed. | |
Handle of figure to print. Note that you cannot specify both this option and the -swindowtitle option. See "Which Figure Is Printed". | |
PostScript and Ghostscript printing only. Use loose bounding box for PostScript output. See "Producing Uncropped Figures". | |
Suppress printing of user interface controls. See "Excluding User Interface Controls". | |
Render using the OpenGL algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -painters. See "Selecting a Renderer". | |
Render using the Painter's algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -opengl. See "Selecting a Renderer". | |
Specify name of printer to use. See "Selecting the Printer". | |
PostScript and built-in raster formats, and Ghostscript vector format only. Specify resolution in dots per inch. Defaults to 90 for Simulink, 150 for figures in image formats and when printing in Z-buffer or OpenGL mode, screen resolution for metafiles, and 864 otherwise. Use -r0 to specify screen resolution. For details, see Resolution Considerations and "Setting the Resolution". | |
Specify name of Simulink system window to print. Note that you cannot specify both this option and the -fhandle option. See "Which Figure Is Printed". | |
Windows printing only. Display the Windows Print dialog box. The v stands for "verbose mode." | |
Render using the Z-buffer algorithm. Note that you cannot specify this method in conjunction with -opengl or -painters. See "Selecting a Renderer". |
Use -rnumber to specify the resolution of the generated output. In general, using a higher value will yield higher quality output but at the cost of larger output files. It affects the resolution and output size of all MATLAB built-in raster formats (which are identified in column four of the table in Graphics Format Files).
Note Built-in graphics formats are generated directly from MATLAB without conversion through the Ghostscript library. Also, in headless (nodisplay) mode, writing to certain image formats is not done by built-in drivers, as it is when a display is being used. These formats are -djpeg, -dtiff, and -dpng. Furthermore, the -dhdf and -dbmp formats cannot be generated in headless mode (but you can substitute -dbmp16m for -dbmp). See Printing and Exporting without a Display for details on printing when not using a display. |
Unlike the built-in MATLAB formats, graphic output generated via Ghostscript does not directly obey -r option settings. However, the intermediate PostScript file generated by MATLAB as input for the Ghostscript processor is affected by the -r setting and thus can indirectly influence the quality of the final Ghostscript generated output.
The effect of the -r option on output quality can be subtle at ordinary magnification when using the OpenGL or ZBuffer renderers and writing to one of the MATLAB built-in raster formats, or when generating vector output that contains an embedded raster image (for example, PostScript or PDF). The effect of specifying higher resolution is more apparent when viewing the output at higher magnification or when printed, since a larger -r setting provides more data to use when scaling the image.
When generating fully vectorized output (as when using the Painters renderer to output a vector format such as PostScript or PDF), the resolution setting affects the degree of detail of the output; setting resolution higher generates crisper output (but small changes in the resolution may have no observable effect). For example, the gap widths of lines that do not use a solid ('-') linestyle can be affected.
MATLAB printing supports a number of standard paper sizes. You can select from the following list by setting the PaperType property of the figure or selecting a supported paper size from the Print dialog box.
Size (Width by Height) | |
|---|---|
8.5 by 11 inches | |
8.5 by 14 inches | |
11 by 17 inches | |
841 by 1189 mm | |
594 by 841 mm | |
420 by 594 mm | |
297 by 420 mm | |
210 by 297 mm | |
148 by 210 mm | |
1029 by 1456 mm | |
728 by 1028 mm | |
514 by 728 mm | |
364 by 514 mm | |
257 by 364 mm | |
182 by 257 mm | |
9 by 12 inches | |
12 by 18 inches | |
18 by 24 inches | |
24 by 36 inches | |
36 by 48 inches | |
8.5 by 11 inches | |
11 by 17 inches | |
17 by 22 inches | |
22 by 34 inches | |
34 by 43 inches |
The print command produces a warning when you print a figure having a callback routine defined for the figure ResizeFcn. To avoid the warning, set the figure PaperPositionMode property to auto or select Match Figure Screen Size in the File > Page Setup dialog box.
If you encounter problems such as segmentation violations, general protection faults, or application errors, or the output does not appear as you expect when using Microsoft printer drivers, try the following:
If your printer is PostScript compatible, print with one of the MATLAB built-in PostScript drivers. There are various PostScript device options that you can use with print , which all start with -dps.
The behavior you are experiencing might occur only with certain versions of the print driver. Contact the print driver vendor for information on how to obtain and install a different driver.
Try printing with one of the MATLAB built-in Ghostscript devices. These devices use Ghostscript to convert PostScript files into other formats, such as HP LaserJet, PCX, Canon BubbleJet, and so on.
Copy the figure as a Windows Enhanced Metafile using the Edit > Copy Figure menu item on the figure window menu or the print -dmeta option at the command line. You can then import the file into another application for printing.
You can set copy options in the figure's File > Preferences > Copying Options dialog box. The Windows Enhanced Metafile Clipboard format produces a better quality image than Windows Bitmap.
You can generally obtain better results when printing a figure window that contains MATLAB uicontrols by setting these key properties:
Set the figure PaperPositionMode property to auto. This ensures that the printed version is the same size as the on-screen version. With PaperPositionMode set to auto MATLAB, does not resize the figure to fit the current value of the PaperPosition. This is particularly important if you have specified a figure ResizeFcn, because if MATLAB resizes the figure during the print operation, ResizeFcn is automatically called.
To set PaperPositionMode on the current figure, use the command:
set(gcf,'PaperPositionMode','auto')
Set the figure InvertHardcopy property to off. By default, MATLAB changes the figure background color of printed output to white, but does not change the color of uicontrols. If you have set the background color, for example, to match the gray of the GUI devices, you must set InvertHardcopy to off to preserve the color scheme.
To set InvertHardcopy on the current figure, use the command:
set(gcf,'InvertHardcopy','off')
Use a color device if you want lines and text that are in color on the screen to be written to the output file as colored objects. Black and white devices convert colored lines and text to black or white to provide the best contrast with the background and to avoid dithering.
Use the print command's -loose option to keep a bounding box from being too tightly wrapped around objects contained in the figure. This is important if you have intentionally used space between uicontrols or axes and the edge of the figure and you want to maintain this appearance in the printed output.
If you print or export in nodisplay mode, none of the uicontrols the figure has will be visible. If you run code that adds uicontrols to a figure when the figure is invisible, the controls will not print until the figure is made visible.
You can print MATLAB surface objects (such as graphs created with surf or mesh) using interpolated colors. However, only patch objects that are composed of triangular faces can be printed using interpolated shading.
Printed output is always interpolated in RGB space, not in the colormap colors. This means that if you are using indexed color and interpolated face coloring, the printed output can look different from what is displayed on screen.
PostScript files generated for interpolated shading contain the color information of the graphics object's vertices and require the printer to perform the interpolation calculations. This can take an excessive amount of time and in some cases, printers might time out before finishing the print job. One solution to this problem is to interpolate the data and generate a greater number of faces, which can then be flat shaded.
To ensure that the printed output matches what you see on the screen, print using the -zbuffer option. To obtain higher resolution (for example, to make text look better), use the -r option to increase the resolution. There is, however, a tradeoff between the resolution and the size of the created PostScript file, which can be quite large at higher resolutions. The default resolution of 150 dpi generally produces good results. You can reduce the size of the output file by making the figure smaller before printing it and setting the figure PaperPositionMode to auto, or by just setting the PaperPosition property to a smaller size.
You can print a noncurrent figure by specifying the figure's handle. If a figure has the title "Figure 2", its handle is 2. The syntax is:
print -fhandle
This example prints the figure whose handle is 2, regardless of which figure is the current figure:
print -f2
Note You must use the -f option if the figure's handle is hidden (i.e., its HandleVisibility property is set to off). |
This example saves the figure with the handle -f2 to a PostScript file named Figure2, which can be printed later:
print -f2 -dps 'Figure2.ps'
If the figure uses noninteger handles, use the figure command to get its value, and then pass it in as the first argument. For example:
h = figure('IntegerHandle','off')
print h -dps2
You can also pass a figure handle as a variable to the function form of print. For example:
h = figure; plot(1:4,5:8) print(h)
This example uses the function form of print to enable a file name to be passed in as a variable:
filename = 'mydata';
print('-f3', '-dpsc', filename);
(Because a file name is specified, the figure will be printed to a file.)
This example combines the previous two examples and uses the function form to print using both a handle variable and a file name variable:
h = figure; plot(1:4,5:8) filename = 'mydata'; print(h, '-dpsc', filename);
(Because a file name is specified, the figure will be printed to a file.)
To print a noncurrent Simulink model, use the -s option with the title of the window. For example, this command prints the Simulink window titled f14:
print -sf14
If the window title includes any spaces, you must call the function form rather than the command form of print. For example, this command saves the Simulink window title Thruster Control:
print('-sThruster Control')
To print the current system, use:
print -s
For information about issues specific to printing Simulink windows, see the Simulink documentation.
This example prints a surface plot with interpolated shading. Setting the current figure's (gcf) PaperPositionMode to auto enables you to resize the figure window and print it at the size you see on the screen. See Printing Options and Printing Interpolated Shading with PostScript Drivers for information on the -zbuffer and -r200 options.
surf(peaks) shading interp set(gcf,'PaperPositionMode','auto') print -dpsc2 -zbuffer -r200
For additional details, see "Printing Images" in the MATLAB Graphics documentation.
You can use the function form of print to pass variables containing file names. For example, this for loop uses file names stored in a cell array to create a series of graphs and prints each one with a different file name:
fnames = {'file1', 'file2', 'file3'};
for k=1:length(fnames)
surf(peaks)
print('-dtiff','-r200',fnames{k})
end
The command
print -depsc -tiff -r300 picture1
saves the current figure at 300 dpi, in a color Encapsulated PostScript file named picture1.eps. The -tiff option creates a 72 dpi TIFF preview, which many word processor applications can display on screen after you import the EPS file. This enables you to view the picture on screen within your word processor and print the document to a PostScript printer using a resolution of 300 dpi.
figure, hgsave, imwrite, orient, printdlg, printopt, saveas
![]() | primes | printdlg | ![]() |

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