Home > FMAToolbox > Plot > Subpanel.m

Subpanel

PURPOSE ^

Subpanel - Add an (invisible) panel container to a figure.

SYNOPSIS ^

function panel = Subpanel(m,n,p,varargin)

DESCRIPTION ^

Subpanel - Add an (invisible) panel container to a figure.

  USAGE

    h = Subpanel(m,n,p,<options>)

    m,n,p          panel position as in <a href="matlab:help subplot">subplot</a>
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'parent'      panel parent handle (default = gcf)
    =========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function panel = Subpanel(m,n,p,varargin)
0002 
0003 %Subpanel - Add an (invisible) panel container to a figure.
0004 %
0005 %  USAGE
0006 %
0007 %    h = Subpanel(m,n,p,<options>)
0008 %
0009 %    m,n,p          panel position as in <a href="matlab:help subplot">subplot</a>
0010 %    <options>      optional list of property-value pairs (see table below)
0011 %
0012 %    =========================================================================
0013 %     Properties    Values
0014 %    -------------------------------------------------------------------------
0015 %     'parent'      panel parent handle (default = gcf)
0016 %    =========================================================================
0017 %
0018 
0019 % Copyright (C) 2010-2011 by Michaƫl Zugaro
0020 %
0021 % This program is free software; you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation; either version 3 of the License, or
0024 % (at your option) any later version.
0025 
0026 % Default values
0027 parent = [];
0028 
0029 % Check number of parameters
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 % Parse parameter list
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 % Create panel (where the corresponding subplot would be)
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 % Change appearance
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);

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005