-
Notifications
You must be signed in to change notification settings - Fork 0
/
tilefigs.m
102 lines (84 loc) · 3.46 KB
/
tilefigs.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% FROM:
% http://home.online.no/~pjacklam/matlab/software/util/graphutil/tilefigs.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function tilefigs(figs)
%TILEFIGS Tile all open figure windows around on the screen.
%
% TILEFIGS places all open figure windows around on the screen with no
% overlap.
%
% TILEFIGS(FIGS) can be used to specify which figures that should be
% tiled. Figures are not sorted when specified.
%
% See also SORTFIGS, CYCLEFIGS.
% Author: Peter John Acklam
% Time-stamp: 2003-10-13 15:40:11 +0200
% E-mail: pjacklam@online.no
% URL: http://home.online.no/~pjacklam
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Get the handles to the figures to process.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~nargin % If no input arguments...
figs = findobj('Type', 'figure'); % ...find all figures.
figs = sort(figs);
end
if isempty(figs)
disp('No open figures or no figures specified.');
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The elements in the vector specifying the position.
% 1 - Window left position
% 2 - Window bottom position
% 3 - Window horizontal size
% 4 - Window vertical size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%hspc = 20; % Horisontal space.
%topspc = 20; % Space above top figure.
%medspc = 20; % Space between figures.
%botspc = 40; % Space below bottom figure.
%
%units = 'pixels';
hspc = 0.02; % Horisontal space.
topspc = 0.02; % Space above top figure.
medspc = 0.02; % Space between figures.
botspc = 0.05; % Space below bottom figure.
units = 'normalized';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set miscellaneous parameter.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nfigs = length(figs); % Number of figures.
nh = ceil(sqrt(nfigs)); % Number of figures horisontally.
nv = ceil(nfigs / nh); % Number of figures vertically.
nh = max(nh, 2);
nv = max(nv, 2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Get the screen size.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
old_root_units = get(0, 'Units'); % Get current root units.
set(0, 'Units', units); % Set root units.
scrdim = get(0, 'ScreenSize'); % Get screen size.
set(0, 'Units', old_root_units); % Reset units.
scrwid = scrdim(3); % Screen width.
scrhgt = scrdim(4); % Screen height.
figwid = (scrwid - (nh + 1) * hspc) / nh;
fighgt = (scrhgt - (topspc + botspc) - (nv - 1) * medspc) / nv;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Put the figures where they belong.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for row = 1 : nv
for col = 1 : nh
idx = (row - 1) * nh + col;
if idx <= nfigs
figlft = col * hspc + (col - 1) * figwid;
figbot = scrhgt - topspc - row * fighgt - (row - 1) * medspc;
figpos = [ figlft figbot figwid fighgt ]; % Figure position.
fighnd = figs(idx); % Figure handle.
old_fig_units = get(fighnd, 'Units'); % Get current units.
set(fighnd, 'Units', units); % Set new units.
set(fighnd, 'OuterPosition', figpos); % Set position.
set(fighnd, 'Units', old_fig_units); % Reset units.
figure(fighnd); % Raise figure.
end
end
end