Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sldrawmultiellipse
Home > sltoolbox > visualize > sldrawmultiellipse.m

sldrawmultiellipse

PURPOSE ^

SLDRAWMULTIELLIPSE Draws multiple ellipses on axies

SYNOPSIS ^

function h = sldrawmultiellipse(centers, vars, npts, plotsyms, varargin)

DESCRIPTION ^

SLDRAWMULTIELLIPSE Draws multiple ellipses on axies

 $ Syntax $
   - sldrawmultiellipse(centers, vars, npts)
   - sldrawmultiellipse(centers, vars, npts, plotsyms, ...)
   - h = sldrawmultiellipse(...)

 $ Arguments $
   - centers:      the centers of the ellipse 
   - vars:         the variances/covariances of the ellipses
   - npts:         the number of sample points on each ellipses
                   (default = 300)
   - plotsyms:     the cell array of plot symbols charcterizing the
                   ellipses. It can be a char string, representing
                   the symbol shared by all ellipses, or a cell array
                   of symbols for different ellipses.
   - h:            the column array of numbers identifying the plots

 $ Description $
    - sldrawmultiellipse(centers, vars, npts) plots one or multiple
      ellipses on the same axis. The ellipses are charcterized by 
      gaussian models parameterized by their centers and variances/
      covariances. The plots are based on sampling points on the 
      ellipse with Mahalanobis distance being 1. The number of samples
      are specified through npts. 
      If there are k ellipses, centers should be a 2 x k matrix, while
      the vars can be either of the following forms:
           - 1 x k matrix:     isotropic variance 
           - 2 x k matrix:     diagonal variance
           - 2 x 2 x k array:  normal covariance
      If the variances/covariances are shared by all ellipses, they
      can be encapsulated in a cell.
           - {1 x 1 scalar}:   shared isotropic variance
           - {2 x 1 vector}:   shared diagonal variance
           - {2 x 2 matrix}:   shared covariance matrix
           
 $ Remarks $
   - It is based on sldrawellipse for plotting.

 $ History $
   - Created by Dahua Lin, on Aug 26, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • sldrawellipse SLDRAWELLIPSE Draws an ellipse on current axis
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function h = sldrawmultiellipse(centers, vars, npts, plotsyms, varargin)
0002 %SLDRAWMULTIELLIPSE Draws multiple ellipses on axies
0003 %
0004 % $ Syntax $
0005 %   - sldrawmultiellipse(centers, vars, npts)
0006 %   - sldrawmultiellipse(centers, vars, npts, plotsyms, ...)
0007 %   - h = sldrawmultiellipse(...)
0008 %
0009 % $ Arguments $
0010 %   - centers:      the centers of the ellipse
0011 %   - vars:         the variances/covariances of the ellipses
0012 %   - npts:         the number of sample points on each ellipses
0013 %                   (default = 300)
0014 %   - plotsyms:     the cell array of plot symbols charcterizing the
0015 %                   ellipses. It can be a char string, representing
0016 %                   the symbol shared by all ellipses, or a cell array
0017 %                   of symbols for different ellipses.
0018 %   - h:            the column array of numbers identifying the plots
0019 %
0020 % $ Description $
0021 %    - sldrawmultiellipse(centers, vars, npts) plots one or multiple
0022 %      ellipses on the same axis. The ellipses are charcterized by
0023 %      gaussian models parameterized by their centers and variances/
0024 %      covariances. The plots are based on sampling points on the
0025 %      ellipse with Mahalanobis distance being 1. The number of samples
0026 %      are specified through npts.
0027 %      If there are k ellipses, centers should be a 2 x k matrix, while
0028 %      the vars can be either of the following forms:
0029 %           - 1 x k matrix:     isotropic variance
0030 %           - 2 x k matrix:     diagonal variance
0031 %           - 2 x 2 x k array:  normal covariance
0032 %      If the variances/covariances are shared by all ellipses, they
0033 %      can be encapsulated in a cell.
0034 %           - {1 x 1 scalar}:   shared isotropic variance
0035 %           - {2 x 1 vector}:   shared diagonal variance
0036 %           - {2 x 2 matrix}:   shared covariance matrix
0037 %
0038 % $ Remarks $
0039 %   - It is based on sldrawellipse for plotting.
0040 %
0041 % $ History $
0042 %   - Created by Dahua Lin, on Aug 26, 2006
0043 %
0044 
0045 %% parse and verify input arguments
0046 
0047 if nargin < 2
0048     raise_lackinput('sldrawmultiellipse', 2);
0049 end
0050 
0051 if ndims(centers) ~= 2 || size(centers, 1) ~= 2
0052     error('sltoolbox:invalidarg', ...
0053         'centers should be a 2 x k matrix');
0054 end
0055 
0056 k = size(centers, 2);
0057 
0058 % parse variance/covariance
0059 
0060 if isnumeric(vars)
0061     if isequal(size(vars), [1 k])
0062         varform = 1;
0063     elseif isequal(size(vars), [2 k])
0064         varform = 2;
0065     elseif isequal(size(vars), [2 2 k])
0066         varform = 3;
0067     else
0068         error('sltoolbox:sizmismatch', ...
0069             'The size of vars is illegal');
0070     end
0071     sharevar = false;
0072 elseif iscell(vars) && numel(vars) == 1
0073     vars = vars{1};
0074     if isequal(size(vars), [1 1])
0075         varform = 1;
0076     elseif isequal(size(vars), [2 1])
0077         varform = 2;
0078     elseif isequal(size(vars), [2 2])
0079         varform = 3;
0080     else
0081         error('sltoolbox:sizmismatch', ...
0082             'The size of vars is illegal');
0083     end
0084     sharevar = true;
0085 end
0086 
0087 if nargin < 3 || isempty(npts)
0088     npts = 300;
0089 end
0090 
0091 if nargin < 4 || isempty(plotsyms)
0092     plotsyms = dme_default_plotsyms(k);
0093 else
0094     if ischar(plotsyms)
0095         ch = plotsyms;
0096         plotsyms = cell(1, k);
0097         [plotsyms{:}] = deal(ch);
0098     elseif iscell(plotsyms)
0099         if length(plotsyms) ~= k
0100             error('sltoolbox:sizmismatch', ...
0101                 'The length of plotsyms is inconsistent with the number of ellipses');
0102         end
0103     else
0104         error('sltoolbox:sizmismatch', ...
0105             'The plotsyms should be either a string or a cell array');
0106     end
0107 end
0108 
0109 if nargin < 5
0110     plotprops = {};
0111 else
0112     plotprops = varargin;
0113 end
0114 
0115 if nargout >= 1
0116     outh = true;
0117     h = zeros(k, 1);
0118 else
0119     outh = false;
0120 end
0121 
0122 %% Main body
0123 
0124 for i = 1 : k
0125     vcenter = centers(:, i);
0126     mcov = dme_get_cov(vars, i, varform, sharevar);
0127     curh = sldrawellipse(vcenter, mcov, npts, plotsyms{i}, plotprops{:});
0128     if outh 
0129         h(i) = curh;
0130     end
0131 end
0132 
0133 
0134 %% Auxiliary functions
0135 
0136 function r = dme_default_plotsyms(n)
0137 
0138 pss = {'b-', 'g-', 'r-', 'c-', 'm-', 'y-', 'k-'};
0139 inds = mod(0:n-1, 7) + 1;
0140 r = pss(inds);
0141 
0142 function C = dme_get_cov(vars, i, varform, sharevar)
0143 
0144 switch varform 
0145     case 1
0146         if sharevar
0147             C = [vars 0; 0 vars];
0148         else
0149             C = [vars(i) 0; 0 vars(i)];
0150         end
0151     case 2
0152         if sharevar
0153             C = diag(vars);
0154         else
0155             C = diag(vars(:, i));
0156         end
0157     case 3
0158         if sharevar
0159             C = vars;
0160         else
0161             C = vars(:,:,i);
0162         end            
0163 end
0164     
0165     
0166 
0167 
0168 
0169 
0170 
0171 
0172 
0173 
0174     
0175     
0176

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com