-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoArrangeFigures.m
108 lines (95 loc) · 2.73 KB
/
autoArrangeFigures.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
103
104
105
106
107
108
function autoArrangeFigures(NH, NW, monitor_id)
% INPUT :
% NH : number of grid of vertical direction
% NW : number of grid of horizontal direction
% OUTPUT :
%
% get every figures that are opened now and arrange them.
%
% autoArrangeFigures selects automatically Monitor1.
% If you are dual(or more than that) monitor user, I recommend to set wide
% monitor as Monitor1.
%
% if you want arrange automatically, type 'autoArrangeFigures(0,0)' or 'autoArrangeFigures()'.
% But maximum number of figures for automatic mode is 27.
%
% if you want specify grid for figures, give numbers for parameters.
% but if your grid size is smaller than required one for accommodating
% all figures, this function changes to automatic mode and if more
% figures are opend than maximum number, then it gives error.
%
% Notes
% + 2017.1.20 use monitor id(Adam Danz's idea)
%
% leejaejun, Koreatech, Korea Republic, 2014.12.13
if nargin < 2
NH = 0;
NW = 0;
monitor_id = 1;
end
task_bar_offset = [30 50];
%%
N_FIG = NH * NW;
if N_FIG == 0
autoArrange = 1;
else
autoArrange = 0;
end
figHandle = sortFigureHandles(findobj('Type','figure'));
n_fig = size(figHandle,1);
if n_fig <= 0
warning('figures are not found');
return
end
screen_sz = get(0,'MonitorPositions');
screen_sz = screen_sz(monitor_id, :);
scn_w = screen_sz(3) - task_bar_offset(1);
scn_h = screen_sz(4) - task_bar_offset(2);
scn_w_begin = screen_sz(1) + task_bar_offset(1);
scn_h_begin = screen_sz(2) + task_bar_offset(2);
if autoArrange==0
if n_fig > N_FIG
autoArrange = 1;
warning('too many figures than you told. change to autoArrange');
else
nh = NH;
nw = NW;
end
end
if autoArrange == 1
grid = [2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4;
3 3 3 3 3 3 3 3 4 4 4 5 5 5 5 5 5 5 5 6 6 6 7 7 7 7 7]';
if n_fig > length(grid)
warning('too many figures(maximum = %d)',length(grid))
return
end
if scn_w > scn_h
nh = grid(n_fig,1);
nw = grid(n_fig,2);
else
nh = grid(n_fig,2);
nw = grid(n_fig,1);
end
end
fig_width = scn_w/nw;
fig_height = scn_h/nh;
fig_cnt = 1;
for i=1:1:nh
for k=1:1:nw
if fig_cnt>n_fig
return
end
fig_pos = [scn_w_begin+fig_width*(k-1) ...
scn_h_begin+scn_h-fig_height*i ...
fig_width ...
fig_height];
set(figHandle(fig_cnt),'OuterPosition',fig_pos);
fig_cnt = fig_cnt + 1;
end
end
end
function figSorted = sortFigureHandles(figs)
[tmp, idx] = sort([figs.Number]);
figSorted = figs(idx);
end