-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadjacentFigs.m
103 lines (98 loc) · 2.88 KB
/
adjacentFigs.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
function [figH, ax1, ax2, varargout] = adjacentFigs(input)
% [figH, ax1, ax2] = adjacentFigs(input)
%
% Function takes two separate figures and positions them horizontally next
% to each other as subplots of the same figure. The function is useful when
% creating live script.
% input is a structure variable with following fields:
% figFolder - folder with figures.
% figname1
% figname2
% figname3 (optional)
% xlim1
% xlim2
% xlim3 (optional)
% ylim1
% ylim2
% ylim3 (optional)
% legendLocation1
% legendLocation2
% legendLocation3 (optional)
% figSize (optional)
% tight (optional).
% Output: figH - a handle to the newly created figure.
% ax1 - the first axes handle.
% ax2 - the second axes handle.
% ax3 - the second axes handle (in the case of three figures).
if ~isfield(input,'xlim1')
input.xlim1 = [0.01 120];
end
if ~isfield(input,'ylim1')
input.ylim1 = [-pi pi];
end
if ~isfield(input,'legendLocation1')
input.legendLocation1 = 'NorthEast';
end
if ~isfield(input,'xlim2')
input.xlim2 = [0.01 120];
end
if ~isfield(input,'ylim2')
input.ylim2 = [-pi pi];
end
if ~isfield(input,'legendLocation2')
input.legendLocation2 = 'NorthEast';
end
if ~isfield(input,'xlim3')
input.xlim3 = [0.01 120];
end
if ~isfield(input,'ylim3')
input.ylim3 = [-pi pi];
end
if ~isfield(input,'legendLocation3')
input.legendLocation3 = 'NorthEast';
end
if ~isfield(input,'figSize')
input.figSize = [];
end
if ~isfield(input,'tight')
input.tight = false;
end
if ~isfield(input,'figPos')
input.tight = [];
end
[figH, ax1] = fig2liveEditor([input.figFolder filesep input.figname1], input.xlim1, input.ylim1, input.legendLocation1, input.figSize, input.tight);
%ax1.XTickLabel = {'-\pi','-\pi/2','0','\pi/2','\pi'};
[~, ax2] = fig2liveEditor([input.figFolder filesep input.figname2], input.xlim2, input.ylim2, input.legendLocation2, input.figSize, input.tight);
set(ax2, 'Parent',figH);
if isfield(input, 'figname3') && ~isempty(input.figname3)
if ~isfield(input, 'xlim3')
input.xlim3 = [];
end
if ~isfield(input, 'ylim3')
input.ylim3 = [];
end
if ~isfield(input, 'legendLocation3')
input.legendLocation3 = [];
end
[~, ax3] = fig2liveEditor([input.figFolder filesep input.figname3], input.xlim3, input.ylim3, input.legendLocation3, input.figSize, input.tight);
set(ax3, 'Parent',figH);
varargout{1} = ax3;
end
if exist('ax3','var')
subplot(1,3,1,ax1);
subplot(1,3,2,ax2);
subplot(1,3,3,ax3);
if isfield(input, 'figPos') && ~isempty(input.figPos)
set(figH, 'Position', input.figPos)
else
set(figH, 'Position', [0 0 1800 500])
end
else
subplot(1,2,1,ax1);
subplot(1,2,2,ax2);
if isfield(input, 'figPos') && ~isempty(input.figPos)
set(figH, 'Position', input.figPos)
else
set(figH, 'Position', [0 0 1200 500])
end
end