File Exchange

image thumbnail


version (2.97 KB) by Richard Quist
Easily print/export figure at on-screen size


Updated 01 Sep 2016

View License

SAVESAMESIZE print/export figure (h) at same size as on screen.
SAVESAMESIZE will adjust printing/exporting related properties so the
figure (h) will print/export the same size as the onscreen display. It
will print/export the figure and then restore the changed properties to
the original values
saveSameSize accepts some optional parameter-value pairs. If used you must
specify BOTH the parameter name (e.g. 'format') AND the parameter value
(e.g. 'png'):
parameter value/meaning
---------- --------------------------------------
'format' output format to generate.
Must be one of the formats supported by the print command

If not specified, jpeg is used as the default

'file' path/name of output file to create

If not specified, 'figure<N>.<ext>' will be used
where <N> is the figure handle and ext
<ext> is the extension corresponding to the
output format chosen

'renderer' Renderer to use when creating the output.
Must be one renderers supported by MATLAB

If not specified, the figure's current renderer will be used

Example usage:
% save current figure to jpeg file named figure<n>.jpg using the
% figure's current renderer

% save current figure to png file named test.png using the
% OpenGL renderer
saveSameSize(gcf, 'format', 'png', 'renderer', 'opengl',...
'file', 'test.png');

See also PRINT

Copyright 2007 The MathWorks, Inc.

Comments and Ratings (8)

Jason West

Excellent function that I wish I had known about earlier. I needed to save files to a precise resolution for export to an external program, and this accomplished just that.

Liaofan Lin


Emery Ku

Many thanks!!

Nick Steinmetz

Works great - MATLAB was resizing my text boxes and legends, causing them to overlap with the data in the figures. I just slid this function in where I had been using the regular "saveas" and worries all gone. Perfect!

jarek tuszynski

Great function. It took me hours to discover that this functionality was not part of MATLAB and that external add-on is needed to perform this basic MATLAB function. Quite shocking.

shan baash

Very useful code to print it to the same size


Updated license

tweaking description

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor