VERB_code_2.3
subplot1.m
1 function AX=subplot1(M,N,varargin);
2 %-------------------------------------------------------------------------
3 % subplot1 function An improved subplot function
4 % Input : - If more than one input arguments are given,
5 % then the first parameter is the number of rows.
6 % If single input argument is given, then this is the
7 % subplot-number for which to set focus.
8 % This could a scalar or two element vector (I,J).
9 % - Number of columns.
10 % * variable number of parameters
11 % (in pairs: ...,Keywoard, Value,...)
12 % - 'Min' : X, Y lower position of lowest subplot,
13 % default is [0.10 0.10].
14 % - 'Max' : X, Y largest position of highest subplot,
15 % default is [0.95 0.95].
16 % - 'Gap' : X,Y gaps between subplots,
17 % default is [0.01 0.01].
18 % - 'XTickL' : x ticks labels option,
19 % 'Margin' : plot only XTickLabels in the
20 % subplot of the lowest row (default).
21 % 'All' : plot XTickLabels in all subplots.
22 % 'None' : don't plot XTickLabels in subplots.
23 % - 'YTickL' : y ticks labels option,
24 % 'Margin' : plot only YTickLabels in the
25 % subplot of the lowest row (defailt).
26 % 'All' : plot YTickLabels in all subplots.
27 % 'None' : don't plot YTickLabels in subplots.
28 % - 'FontS' : axis font size, default is 10.
29 % 'XScale' : scale of x axis:
30 % 'linear', default.
31 % 'log'
32 % - 'YScale' : scale of y axis:
33 % 'linear', default.
34 % 'log'
35 % Example: subplot1(2,2,'Gap',[0.02 0.02]);
36 % subplot1(2,3,'Gap',[0.02 0.02],'XTickL','None','YTickL','All','FontS',16);
37 % See also : subplot1c.m
38 % Tested : Matlab 5.3
39 % By : Eran O. Ofek June 2002
40 % URL : http://wise-obs.tau.ac.il/~eran/matlab.html
41 %-------------------------------------------------------------------------
42 MinDef = [0.10 0.10];
43 MaxDef = [0.95 0.95];
44 GapDef = [0.01 0.01];
45 XTickLDef = 'Margin';
46 YTickLDef = 'Margin';
47 FontSDef = 10;
48 XScaleDef = 'linear';
49 YScaleDef = 'linear';
50 
51 % set default parameters
52 Min = MinDef;
53 Max = MaxDef;
54 Gap = GapDef;
55 XTickL = XTickLDef;
56 YTickL = YTickLDef;
57 FontS = FontSDef;
58 XScale = XScaleDef;
59 YScale = YScaleDef;
60 
61 
62 MoveFoc = 0;
63 if (nargin==1),
64  %--- move focus to subplot # ---
65  MoveFoc = 1;
66 elseif (nargin==2),
67  % do nothing
68 elseif (nargin>2),
69  Narg = length(varargin);
70  if (0.5.*Narg==floor(0.5.*Narg)),
71 
72  for I=1:2:Narg-1,
73  switch varargin{I},
74  case 'Min'
75  Min = varargin{I+1};
76  case 'Max'
77  Max = varargin{I+1};
78  case 'Gap'
79  Gap = varargin{I+1};
80  case 'XTickL'
81  XTickL = varargin{I+1};
82  case 'YTickL'
83  YTickL = varargin{I+1};
84  case 'FontS'
85  FontS = varargin{I+1};
86  case 'XScale'
87  XScale = varargin{I+1};
88  case 'YScale'
89  YScale = varargin{I+1};
90  otherwise
91  error('Unknown keyword');
92  end
93  end
94  else
95  error('Optional arguments should given as keyword, value');
96  end
97 else
98  error('Illegal number of input arguments');
99 end
100 
101 
102 
103 
104 
105 
106 
107 
108 switch MoveFoc
109  case 1
110  %--- move focus to subplot # ---
111  H = get(gcf,'Children');
112 % Ptot = length(H);
113  Ptot = sum(strcmp(get(H,'type'),'axes'));
114  if (length(M)==1),
115  M = Ptot - M + 1;
116  elseif (length(M)==2),
117  %--- check for subplot size ---
118  Pos1 = get(H(1),'Position');
119  Pos1x = Pos1(1);
120  for Icheck=2:1:Ptot,
121  PosN = get(H(Icheck),'Position');
122  PosNx = PosN(1);
123  if (PosNx==Pos1x),
124  NumberOfCol = Icheck - 1;
125  break;
126  end
127  end
128  NumberOfRow = Ptot./NumberOfCol;
129 
130  Row = M(1);
131  Col = M(2);
132 
133  M = (Row-1).*NumberOfCol + Col;
134  M = Ptot - M + 1;
135  else
136  error('Unknown option, undefined subplot index');
137  end
138 
139  set(gcf,'CurrentAxes',H(M));
140 
141  case 0
142  %--- open subplots ---
143 
144  Xmin = Min(1);
145  Ymin = Min(2);
146  Xmax = Max(1);
147  Ymax = Max(2);
148  Xgap = Gap(1);
149  Ygap = Gap(2);
150 
151 
152  Xsize = (Xmax - Xmin)./N;
153  Ysize = (Ymax - Ymin)./M;
154 
155  Xbox = Xsize - Xgap;
156  Ybox = Ysize - Ygap;
157 
158 
159  Ptot = M.*N;
160 
161  Hgcf = gcf;
162  clf;
163  figure(Hgcf);
164  for Pi=1:1:Ptot,
165  Row = ceil(Pi./N);
166  Col = Pi - (Row - 1)*N;
167 
168  Xstart = Xmin + Xsize.*(Col - 1);
169  Ystart = Ymax - Ysize.*Row;
170 
171 % subplot(M,N,Pi);
172 % hold on;
173 
174  if (false && Col == N) % N
175  axes('position',[Xstart,Ystart,Xbox+max(min((Xbox+0.02)/3,0.02+0.02)+0.02,0.007),Ybox]);
176  else
177  AX(Pi) = axes('position',[Xstart,Ystart,Xbox,Ybox]);
178  end
179 
180  %set(gca,'position',[Xstart,Ystart,Xbox,Ybox]);
181 % set(gca,'FontSize',FontS);
182  box on;
183  hold on;
184 
185  switch XTickL
186  case 'Margin'
187  if (Row~=M),
188  %--- erase XTickLabel ---
189  set(gca,'XTickLabel',[]);
190  end
191  case 'All'
192  % do nothing
193  case 'None'
194  set(gca,'XTickLabel',[]);
195  otherwise
196  error('Unknown XTickL option');
197  end
198 
199  switch YTickL
200  case 'Margin'
201  if (Col~=1),
202  %--- erase YTickLabel ---
203  set(gca,'YTickLabel',[]);
204  end
205  case 'All'
206  % do nothing
207  case 'None'
208  set(gca,'YTickLabel',[]);
209  otherwise
210  error('Unknown XTickL option');
211  end
212 
213  switch XScale
214  case 'linear'
215  set(gca,'XScale','linear');
216  case 'log'
217  set(gca,'XScale','log');
218  otherwise
219  error('Unknown XScale option');
220  end
221 
222  switch YScale
223  case 'linear'
224  set(gca,'YScale','linear');
225  case 'log'
226  set(gca,'YScale','log');
227  otherwise
228  error('Unknown YScale option');
229  end
230 
231  end
232 
233  otherwise
234  error('Unknown MoveFoc option');
235 end
double max(double v1, double v2)
Return maximum.
void gcf(double *gammcf, double a, double x, double *gln)
Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation as g...
Definition: erf.cpp:103
#define I(l, k)
Specified Index [l][k].
Parameters_structure parameters
Parameters structure, with all parameters from the parameters.ini file. The default parameters define...
Definition: Main.cpp:185