MATLAB Function Reference | ![]() ![]() |
Syntax
print print -device
-options
filename
[pcmd,dev] = printopt
Description
print
and printopt
produce hardcopy 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
specifies a print driver (such as color PostScript) or a graphics-file format (such as TIFF). If the -device
-device
is set to -dmeta
or -dbitmap
(Windows only), the figure is saved to the clipboard. If you omit -device
, print uses the default value stored by printopt
. The Devices section lists all supported device types.
print -
specifies print options that modify the action of the options
print
command. (For example, the -noui
option suppresses printing of user interface controls.) The Options section lists available options.
print
directs the output to the file designated by filename
filename
. If filename
does not include an extension, print
appends an appropriate extension, depending on the driver or format specified (e.g., .ps
or.tif
).
print(...)
is the function form of print. It enables you to pass variables for any input arguments. This form is useful passing filenames and handles. See Batch Processing for an example.
[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 hardcopy 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 |
System Printing Command |
Driver or Format |
UNIX |
|
|
VMS |
|
|
Windows |
COPY /B %s LPT1: |
-dwin |
The table below shows the complete list of printer drivers supported by MATLAB. If you do not specify a driver, MATLAB uses the default setting shown in the previous table.
Some of the drivers are available from a product called GhostScript, which is shipped with MATLAB. The last column indicates when GhostScript is used.
Some drivers are not available on all platforms. This is noted in the first column of the table.
Graphics Format Files
To save your figure as a graphics-format file, specify a format switch and filename. 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 not supported for GhostScript formats.
The table below shows the supported output formats for exporting from MATLAB 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. The first column indicates this by showing "MATLAB" or "GhostScript" in parentheses. The third column indicates which platforms support the format.
The TIFF image format is supported on all platforms by almost all word processors for importing images. JPEG is a lossy, highly compressed format that is supported on all platforms for image processing and for inclusion into HTML documents on the World Wide 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.
This table summarizes options that you can specify for print
. The second column also shows which tutorial sections contain more detailed information. The sections listed are located under Printing and Exporting Figures with MATLAB.
Option |
Description |
-adobecset |
PostScript only. Use PostScript default character set encoding. See Early PostScript 1 Printers. |
-append |
PostScript only. Append figure to existing PostScript file. See Appending Figures to a PostScript File. |
-cmyk |
PostScript only. Print with CMYK colors instead of RGB. See Creating CMYK Output. |
-device |
Printer driver to use. See Specifying a Printer Driver. |
-dsetup |
Display the Print Setup dialog. |
|
Handle of figure to print. Note that you cannot specify both this option and the -s windowtitle option. See Which Figure Is Printed. |
-loose |
PostScript and GhostScript only. Use loose bounding box for PostScript. See Producing Uncropped Output. |
-noui |
Suppress printing of user interface controls. See Excluding User Interface Controls from Output. |
-OpenGL |
Render using the OpenGL algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -painters . See Setting the Rendering Method. |
-painters |
Render using the Painter's algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -OpenGL . See Setting the Rendering Method. |
|
UNIX only. Specify name of printer to use. See Specifying a Printer. |
|
PostScript and GhostScript only. Specify resolution in dots per inch. See Setting Resolution. |
|
Specify name of Simulink system window to print. Note that you cannot specify both this option and the -f handle option. See Which Figure Is Printed. |
-v |
Windows only. Display the Windows Print dialog box. The v stands for "verbose mode." |
-zbuffer |
Render using the Z-buffer algorithm. Note that you cannot specify this method in conjunction with -OpenGL or -painters . See Setting the Rendering Method. |
Paper Sizes
MATLAB 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.
Printing Tips
This section includes information about specific printing issues.
Figures with Resize Functions
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.
Troubleshooting MS-Windows Printing
If you encounter problems such as segmentation violations , general protection faults, application errors, or the output does not appear as you expect when using MS-Windows printer drivers, try the following:
print
command: they all start with -dps
.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 Metafile clipboard format produces a better quality image than Windows Bitmap.
Printing Thick Lines on Windows95
Due to a limitation in Windows95, MATLAB is set up to print lines as either:
LineWidth
)LineStyle
) If you create lines that are thicker than one pixel and use nonsolid line styles, MATLAB prints these lines with the specified line style, but one pixel wide (i.e., as thin lines).
However, you can change this behavior so that MATLAB prints thick, styled lines as thick, solid lines by editing your matlab.ini
file, which is in your Windows directory. In this file, find the section,
[Matlab Settings]
and in this section change the assignment,
ThinLineStyles=1
ThinLineStyles=0
Printing MATLAB GUIs
You can generally obtain better results when printing a figure window that contains MATLAB uicontrol
s
by setting these key properties:
PaperPositionMode
property to auto
. This ensures the printed version is the same size as the onscreen 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, the ResizeFcn
is automatically called. 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 to, for example, match the gray of the GUI devices, you must set InvertHardcopy
to off
to preserve the color scheme. set(gcf,'InvertHardcopy','off')
print
command's -loose
option to prevent MATLAB from using a bounding box that is 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.Notes on Printing Interpolated Shading with PostScript Drivers
MATLAB can print 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, 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 may actually "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 trade-off 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.
lpr
command cannot print files larger than 1 Mbyte unless you use the -s
option, which MATLAB does by default. See the lpr
man page for more information.
Specifying the Figure to Print
You can print a noncurrent figure by specifying the figure's handle. If a figure has the title "Figure No. 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
Note that 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.
h = figure('IntegerHandle','off') print h -depson
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 filename to be passed in as a variable.
filename = 'mydata'; print('-f3', '-dpsc', filename);
(Because a filename is specified, the figure will be printed to a file.)
Specifying the Model to Print
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 a 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 Options and the previous section for information on the -zbuffer
and -r200
options.
surf(peaks) shading interp set(gcf,'PaperPositionMode','auto') print -dpsc2 -zbuffer -r200
You can use the function form of print
to pass variables containing file names. For example, this for loop creates a series of graphs and prints each one with a different file name.
for i=1:length(fnames) surf(Z(:,:,i)) print('-dtiff','-r200',fnames(i)) end
Tiff Preview
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.
See Also
![]() | primes | printdlg | ![]() |