-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddaxes.m
More file actions
33 lines (25 loc) · 799 Bytes
/
addaxes.m
File metadata and controls
33 lines (25 loc) · 799 Bytes
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
function hAx2 = addaxes(hAx1)
if nargin < 1
hAx1 = gca;
end
properties = {'Position' 'Xlim' 'XScale'};
values = get(hAx1, properties);
args = makeNameValuePairs(properties, values);
hAx2 = axes(args{:});
cindex = get(hAx1, 'ColorOrderIndex');
colors = get(hAx2, 'ColorOrder');
color1 = colors(1,:);
color2 = colors(cindex+1, :);
set(hAx2, 'Color', 'none');
set(hAx2, 'YAxisLocation', 'right');
set(hAx2, 'XTick', []);
set(hAx2, 'Box', 'off');
set(hAx2, 'ColorOrderIndex', cindex+1);
set(hAx1, 'YColor', color1);
set(hAx2, 'YColor', color2);
end
function pairs = makeNameValuePairs(names, values)
cell2d = {names{:}; values{:}};
cellflat = {cell2d{:}};
pairs = cellflat;
end