MATLAB Function Reference |
Syntax
print print filename print-d
driver
print -dformat
print -dformat
filename
print -smodelname
print ... -options
[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
directs the output to the file designated by filename
filename
. If filename
does not include an extension, print
appends an appropriate extension.
print -d
prints the figure using the specified printer driver
driver
, (such as color PostScript). If you omit -d
driver
, print uses the default value stored in printopt.m
. The Printer Driver table lists all supported device types.
print -d
copies the figure to the system clipboard (Windows only). A valid format
format
for this operation is either -dmeta
(Windows Enhanced Metafile) or -dbitmap
(Windows Bitmap).
print -d
exports the figure to the specified file using the specified graphics format
filename
format
, (such as TIFF). The Graphics Format table lists all supported graphics file formats.
print -s
prints the current Simulink model modelname
modelname
.
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(...)
is the function form of print
. It enables you to pass variables for any input arguments. This form is useful for 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 |
|
|
Windows |
COPY /B %s LPT1: |
-dwin |
The table below shows the more widely-used printer drivers supported by MATLAB. If you do not specify a driver, MATLAB uses the default setting shown in the previous table. For a list of all supported printer drivers, type
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.
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 also supported for Windows Enhanced Metafiles, JPEG, and PNG files, but 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. All formats except for EMF are supported on both the PC and UNIX platforms.
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 Settings That Are Driver Specific. |
-cmyk |
PostScript only. Print with CMYK colors instead of RGB. See Setting CMYK Color. |
-ddriver |
Printing only. Printer driver to use. See Drivers table. |
-dformat |
Exporting only. Graphics format to use. See Graphics Format Files table. |
-dsetup |
Display the Print Setup dialog. |
-fhandle |
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 Figures. |
-noui |
Suppress printing of user interface controls. See Excluding User Interface Controls. |
-opengl |
Render using the OpenGL algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -painters . See Selecting a Renderer. |
-painters |
Render using the Painter's algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -opengl . See Selecting a Renderer. |
-Pprinter |
Specify name of printer to use. See Selecting Printer. |
-rnumber |
PostScript, JPEG, PNG, and Ghostscript 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. See Setting the Resolution. |
-s windowtitle |
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 Selecting a Renderer. |
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, or 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 Enhanced Metafile clipboard format produces a better quality image than Windows Bitmap.
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, for example, to match the gray of the GUI devices, you must set InvertHardcopy
to off
to preserve the color scheme.
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 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 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 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.
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
This example prints the figure whose handle is 2, regardless of which figure is the current figure.
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.
If the figure uses noninteger handles, use the figure
command to get its value, and then pass it in as the first argument.
You can also pass a figure handle as a variable to the function form of print
. For example,
This example uses the function form of print
to enable a filename to be passed in as a variable.
(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
.
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 Simulink window title Thruster Control
.
To print the current system, use
For information about issues specific to printing Simulink windows, see the Simulink documentation.
Printing Figures at Screen Size
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.
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 filenames 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
Tiff Preview
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 |
© 1994-2005 The MathWorks, Inc.