-
Notifications
You must be signed in to change notification settings - Fork 1
/
set_figure_size.m
66 lines (56 loc) · 1.77 KB
/
set_figure_size.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function set_figure_size(h,sz)
% SET_FIGURE_SIZE Set the output size for a matlab figure.
%
% A frequent problem with Matlab figures is that they are designed to be
% output at 8-by-6 inches. However, most figures are included in papers at
% much smaller sizes. The function adjusts the paper position property of
% a figure based on many different arguments:
%
% set_figure_size('tiny') % set figure size to 1.25 in height
% set_figure_size('small') % set figure size to 2.5 in height
% set_figure_size('medium') % set figure size to 4 in height
% set_figure_size('big'); % Matlab's default (set fig size to 6 in height)
%
% set_figure_size([w,h]); % set figure size to w-by-h inches
% This call respects the figures PaperUnits, so w-by-h would be
% centimeters if PaperUnits is 'centimeters'
%
% set_figure_size(h,...); % set the figure size of the figure with handle h
% this form can work with any of the other
%
% David F. Gleich
% History
% -------
% :2010-02-12: Initial writing
% set up the single call case
if nargin==1
sz = h;
h = gcf;
end
pp = get(h,'PaperPosition');
if ischar(sz)
switch lower(sz)
case 'tiny'
pp(3) = 1.5;
pp(4) = 1.25;
case 'small'
pp(3) = 3;
pp(4) = 2.5;
case 'medium'
pp(3) = 5;
pp(4) = 4;
case 'big'
pp(3) = 8;
pp(4) = 6;
otherwise
error('set_figure_size:unknownSize',...
'the string ''%s'' is not a recognized size', sz);
end
elseif length(sz)==2
pp(3) = sz(1);
pp(4) = sz(2);
else
error('set_figure_size:invalidType',...
'the figure size should be a string or a two-element array');
end
set(h,'PaperPosition',pp);