0001 function panel = Subpanel(m,n,p,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 parent = [];
0028
0029
0030 if nargin < 3,
0031 error('Incorrect number of parameters (type ''help <a href="matlab:help Subpanel">Subpanel</a>'' for details).');
0032 end
0033
0034
0035 for i = 1:2:length(varargin),
0036 if ~ischar(varargin{i}),
0037 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help Subpanel">Subpanel</a>'' for details).']);
0038 end
0039 switch(lower(varargin{i})),
0040 case 'parent',
0041 parent = varargin{i+1};
0042 if ~ishandle(parent),
0043 error('Incorrect value for property ''parent'' (type ''help <a href="matlab:help Subpanel">Subpanel</a>'' for details).');
0044 end
0045 otherwise,
0046 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help Subpanel">Subpanel</a>'' for details).']);
0047 end
0048 end
0049
0050 if isempty(parent), parent = gcf; end
0051
0052
0053 position = [0 0 1 1];
0054 x0 = position(1);
0055 dx = position(3)/n;
0056 y0 = position(2);
0057 dy = position(4)/m;
0058 p = p - 1;
0059 x = rem(p,n);
0060 y = floor(p/n);
0061 X1 = min(x);
0062 Y1 = min(y);
0063 X2 = max(x);
0064 Y2 = max(y);
0065 P = [x0+X1*dx y0+(m-Y2-1)*dy (X2-X1+1)*dx (Y2-Y1+1)*dy];
0066 panel = uipanel('position',P,'parent',parent);
0067
0068
0069 if strcmp(get(parent,'type'),'figure'),
0070 color = get(parent,'color');
0071 elseif strcmp(get(parent,'type'),'uipanel'),
0072 color = get(parent,'backgroundcolor');
0073 else
0074 color = [1 1 1]*0.8;
0075 end
0076 set(panel,'bordertype','none','backgroundcolor',color);