Graphics    

From the Command Line

You can print a MATLAB figure from the command line or from a program. Use the set function to set the properties that control how the printed figure looks. Use the print command to print it to a printer or to a file.

The set Function

The set function changes the values of properties that control the look of a printed figure. These properties are stored with the figure. When you change one of the properties, the new value is saved with the figure and affects each print of the figure until you change the setting again.

To change the print properties of the current figure, the set command has the form

where gcf is a call that gets 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,

sets the units of measure and the paper size. Changing the 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 command to retrieve the value of a specific property.

The print Command

The print command sends the figure to a printer, saves it to a file, exports it to a graphics-format file, or exports it to the clipboard.

The command and function forms of print differ slightly in their syntax. Although this document uses the command form, you can easily use the equivalent function form in a program. In both forms, all arguments are optional and can be placed in any order.

The command form of print is

The function form of print is

where:

-device
For printing, -device is a printer.
For exporting, -device is the graphics format in which the figure is exported.
-options
Controls some aspects of the look of the printed figure. It can also control the action to be taken, or specify the figure to be printed or exported.
filename
Is the name of the file to which the figure is saved, appended, or exported.

You control what action the print command takes, depending on the presence or absence of certain arguments. This table describes what arguments to use. The table assumes factory defaults.

Action
Print Command Arguments
Print a figure to a printer.
Don't specify a filename, and specify a printer.
Print a figure to a file for later printing.
Specify a filename, and specify a printer.
Export a figure to a graphics format file that you can later import into an application.
Specify a filename, and specify a graphics format.
Export a figure in graphics format to the clipboard.
Don't specify a filename, and specify a graphics format.


 Using Print Dialog Boxes Changing the Figure's Settings