-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpsArrange.m
More file actions
49 lines (45 loc) · 1.53 KB
/
cpsArrange.m
File metadata and controls
49 lines (45 loc) · 1.53 KB
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
function cpsArrange(h,opt)
%cpsArrange Rearrange the occlusion in the current Axes
% cpsArrange(H,'back') rearranges graphics object H so that it's
% behind all the other graphics objects in the current Axes.
%
% cpsArrange(H,'front') sends it to the front.
%
% When H is an array of graphics objects, the last element will be
% the frontmost (backmost) object followed by the rest if the option
% is 'front' ('back').
%
% Example:
% patch([0 1 1 0],[1 0 1 2],'b');
% hold on;
% h = plot([0 1],[0 2],'r','LineWidth',10);
% for i = 1:5
% cpsArrange(h,'back');
% pause(1);
% cpsArrange(h,'front');
% pause(1);
% end
%
% Part of <a href="matlab:help cpsPlotTools">cpsPlotTools</a>.
narginchk(2,2)
if ~isgraphics(h)
error('h must be a graphics handle');
end
if ~any(strcmpi(opt,{'front','back'}))
error('Arrange option should be ''front'' or ''back''.');
end
for hi = 1:numel(h)
kids = get(gca,'Children');
thisH = h(hi);
if ~any(kids==thisH)
error('Provided Graphics handle is not in the current axis');
end
if strcmpi(opt,'front')
set(gca,'Children',[kids(kids==thisH); kids(kids~=thisH)]);
elseif strcmpi(opt,'back')
set(gca,'Children',[kids(kids~=thisH); kids(kids==thisH)]);
else
error(['unknown option: ' opt]);
end
end
end