print

Prints a figure or saves it to a file in a chosen format.

Category: Graphics > Printing and Saving

Syntax

print(filename, formatOption)

Saves the current figure, for example print('plot', '-dpng') writes plot.png.

print(fig, filename, formatOption)

Saves the figure fig.

print(___, '-rNNN')

Sets the resolution in dots per inch, such as '-r300'.

print -dpng name

Command form of the same call.

Description

print is the long-standing command for producing output files. It honors the paper properties of the figure (see orient). For new code, exportgraphics is usually simpler, since it crops whitespace and needs no format flag.

Input arguments

filename
File name; the extension is added when omitted.
formatOption
Device flag such as '-dpng', '-djpeg', '-dsvg', '-dpdf'.
'-rNNN'
Resolution in dpi.

Example

Save as PNG

plot(1:5)
try
  print('figure1', '-dpng', '-r150');
  disp('saved figure1.png')
catch
  disp('needs the editor renderer')
end
Output
needs the editor renderer

In the app the file is written and the first message is shown.

Notes

Writing files needs the MatLivre editor's renderer; the headless command-line runtime reports an error, which the example catches.

See also

exportgraphics saveas orient printopt