Main Content

Programmatically Print Models from MATLAB Command Window

Printing Commands

The MATLAB® print command provides several options for printing Simulink® models. For example, print the Compression subsystem in the sldemo_enginewc model to your default printer:

print -sCompression


When you use the print command, you can print only one system. To print multiple levels in a model, use multiple print commands, one for each system that you want to print. To print multiple systems in a model, consider using the Print Model dialog box in the Simulink Editor. For details, see Select the Systems to Print.

You can use set_param and the following parameters to specify printing options for models.

Model Parameters for Printing





Printing paper orientation.

'portrait' | {'landscape'}


When PaperPositionMode is set to manual, this parameter determines the position and size of a diagram on paper and the size of the diagram exported as a graphic file in the units specified by PaperUnits.

vector — [left, bottom, width, height]


Paper position mode.

  • auto

    When printing, Simulink software sizes the diagram to fit the printed page. When exporting a diagram as a graphic image, Simulink software sizes the exported image to be the same size as the diagram's normal size on screen.

  • manual

    When printing, Simulink software positions and sizes the diagram on the page as indicated by PaperPosition. When exporting a diagram as a graphic image, Simulink software sizes the exported graphic to have the height and width specified by PaperPosition.

  • tiled

    Enables tiled printing.

    See Print Large Diagrams on Multiple Pages for more information.

{'auto'} | 'manual' | 'tiled'


Size of PaperType in PaperUnits.

vector — [width height] (read only)


Printing paper type.

'usletter' | 'uslegal' | 'a0' | 'a1' | 'a2' | 'a3' | 'a4' | 'a5' | 'b0' | 'b1' | 'b2' | 'b3' | 'b4' | 'b5' | 'arch-A' | 'arch-B' | 'arch-C' | 'arch-D' | 'arch-E' | 'A' | 'B' | 'C' | 'D' | 'E' | 'tabloid'


Printing paper size units.

'normalized' | {'inches'} | 'centimeters' | 'points'


Controls the size of the margins associated with each tiled page. Each element in the vector represents a margin at the particular edge.

vector — [left, top, right, bottom]

You can use orient to control the paper orientation.

Print Systems with Multiline Names or Names with Spaces

To print a system whose name appears on multiple lines, assign the newline character to a variable and use that variable in the print command. This example shows how to print a subsystem whose name, Aircraft Dynamics Model, appears on three lines.

open_system('f14/Aircraft Dynamics Model');
sys = sprintf('f14/Aircraft\nDynamics\nModel');
print (['-s' sys])

To print a system whose name includes one or more spaces, specify the name as a character vector. For example, to print the Throttle & Manifold subsystem, enter:

open_system('sldemo_enginewc/Throttle & Manifold');
print (['-sThrottle & Manifold'])

Set Paper Orientation and Type

To set just the paper orientation, use the MATLAB orient command.

You can also set the paper orientation by using set_param with the PaperOrientation model parameter. Set the paper type with the PaperType model parameter.

Position and Size a System

To position and size the model diagram on the printed page, use set_param command with the PaperPositionMode and PaperPosition model parameters.

The value of the PaperPosition parameter is a vector of form [left bottom width height]. The first two elements specify the bottom-left corner of a rectangular area on the page, measured from the bottom-left corner. The last two elements specify the width and height of the rectangle.

If you set the PaperPositionMode parameter to manual, Simulink positions (and scales, if necessary) the model to fit inside the specified print rectangle. If PaperPositionMode is auto, Simulink centers the model on the printed page, scaling the model, if necessary, to fit the page.

For example, to print the vdp model in the lower-left corner of a U.S. letter-size page in landscape orientation:

set_param('vdp', 'PaperType', 'usletter');
set_param('vdp', 'PaperOrientation', 'landscape');
set_param('vdp', 'PaperPositionMode', 'manual');
set_param('vdp', 'PaperPosition', [0.5 0.5 4 4]);
print -svdp

Use Tiled Printing

Enable Tiled Printing

  1. Use set_param to set the PaperPositionMode parameter to tiled.

  2. Use the print command with the -tileall argument.

For example, to enable tiled printing for the Compression subsystem in the sldemo_enginewc model:

set_param('sldemo_enginewc/Compression', 'PaperPositionMode', ...
print('-ssldemo_enginewc/Compression', '-tileall')

Display Tiled Page Boundaries

To display the page boundaries programmatically, use the set_param command, with the model parameter ShowPageBoundaries set to on. For example:

set_param('sldemo_enginewc', 'ShowPageBoundaries', 'on')

Set Tiled Page Margins

By decreasing the margin sizes, you can increase the printable area of the tiled pages. To specify the margin sizes associated with tiled pages, use the set_param function with the TiledPaperMargins parameter. Each margin to 0.5 inches by default. The value of TiledPaperMargins is a vector that specifies margins in this order: [left top right bottom]. Each element specifies the size of the margin at a particular edge of the page. The value of the PaperUnits parameter determines the units of measurement for the margins.

Specify Range of Tiled Pages to Print

To specify a range of tiled page numbers programmatically, use print with the -tileall argument and the -pages argument. Append to -pages a two-element vector that specifies the range.


Simulink uses a row-major scheme to number tiled pages. For example, the first page of the first row is 1, the second page of the first row is 2, and so on.

For example, to print the second, third, and fourth pages:

print('-svdp','-tileall','-pages[2 4]')

Print Models to Image File Formats

To print your model to an image file format such as .png or .jpeg, use the -device argument with the MATLAB print command. For example, to print the vdp model to a .png format, use this command:

print -dpng -svdp vdp_model.png

To programmatically export a model into an image format:

  • Call your model in the MATLAB command line.

    model %model is your model name
  • Use the print command to save your model in a .jpeg format.

    print('-smodel', '-djpg', 'new_name')

By default, the canvas (background) of the exported model matches the color of the model. To use a white or transparent canvas for model files that you export to another file format, set the Simulink Preferences > General > Export preference. For more information, see Set Simulink Preferences.

See Also


Related Examples

More About