-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinkfigures.m
53 lines (47 loc) · 1005 Bytes
/
linkfigures.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
function linkfigures(varargin)
% Links figures, like linkaxes but with different figures
%
% Accept the formats:
% linkfigures(1,2,3) or linkfigures([1,2,3]) or linkfigures(1:3)
%
% Note that using the first 2 options, the first figure you specify will state
% the initial axes limits, so you can first zoom in and only then link.
%
% When final input is 'x' links only X axis
% When final input is 'y' links only X axis
% When final input is 'off' breaks links
%
% Created by Yanai Ankri
xOnly = 0;
yOnly = 0;
removeLink = 0;
L = length(varargin);
lastVar = cell2mat(varargin(end));
if ischar(lastVar)
L = L-1;
if strcmp(lastVar , 'x')
xOnly = 1;
end
if strcmp(lastVar , 'y')
yOnly = 1;
end
if strcmp(lastVar , 'off')
removeLink = 1;
end
end
ax = [];
for i=1:L
list = cell2mat(varargin(i));
for j=1:length(list)
ax(end+1) = gca(list(j));
end
end
if xOnly
linkaxes(ax,'x')
elseif yOnly
linkaxes(ax,'y')
elseif removeLink
linkaxes(ax,'off')
else
linkaxes(ax)
end