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 sldrawpts
Home > sltoolbox > visualize > sldrawpts.m

sldrawpts

PURPOSE ^

SLDRAWPTS Draws a set of sample points on axes

SYNOPSIS ^

function h = sldrawpts(X, varargin)

DESCRIPTION ^

 SLDRAWPTS Draws a set of sample points on axes

 $ Syntax $
   - h = sldrawpts(X, ...)
   - h = sldrawpts(X, plotsyms, ...)
   - h = sldrawpts(X, nums, ...)
   - h = sldrawpts(X, nums, plotsyms, ...)

 $ Arguments $
   - X:        the sample matrix with each column as a sample
   - nums:     the number of samples in classes
   - plotsyms: the cell array of plot symbols for classes
               (must be encompassed in a cell array)
   - h:        the a column vector of handles to lineseries objects, 
               one handle per plotted line. 
     
 $ History $
   - Created by Dahua Lin, on Aug 25, 2006
   - Modified by Dahua Lin, on Aug 28, 2006
       - fix the error when nums have zeros

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slnums2bounds SLNUMS2BOUNDS Compute the index-boundaries from section sizes
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function h = sldrawpts(X, varargin)
0002 % SLDRAWPTS Draws a set of sample points on axes
0003 %
0004 % $ Syntax $
0005 %   - h = sldrawpts(X, ...)
0006 %   - h = sldrawpts(X, plotsyms, ...)
0007 %   - h = sldrawpts(X, nums, ...)
0008 %   - h = sldrawpts(X, nums, plotsyms, ...)
0009 %
0010 % $ Arguments $
0011 %   - X:        the sample matrix with each column as a sample
0012 %   - nums:     the number of samples in classes
0013 %   - plotsyms: the cell array of plot symbols for classes
0014 %               (must be encompassed in a cell array)
0015 %   - h:        the a column vector of handles to lineseries objects,
0016 %               one handle per plotted line.
0017 %
0018 % $ History $
0019 %   - Created by Dahua Lin, on Aug 25, 2006
0020 %   - Modified by Dahua Lin, on Aug 28, 2006
0021 %       - fix the error when nums have zeros
0022 %
0023 
0024 %% parse and verify input arguments
0025 
0026 [d, n] = size(X);
0027 if d ~= 2 && d ~= 3
0028     error('sltoolbox:invalidarg', ...
0029         'X should contain 2D or 3D samples');
0030 end
0031 
0032 plotprops = {};
0033 
0034 if nargin == 1
0035     multiclass = false;
0036     plotsyms = default_plotsyms(1);
0037     plotprops = {};
0038     
0039 else
0040     if ~isnumeric(varargin{1})  % single class
0041         multiclass = false;
0042         if ~iscell(varargin{1})
0043             plotsyms = default_plotsyms(1);
0044             pidx = 1;
0045         else
0046             plotsyms = varargin{1};
0047             pidx = 2;
0048         end
0049         
0050     else                        % multi class
0051         multiclass = true;
0052         nums = varargin{1};
0053         nums = nums(:)';
0054         if sum(nums) ~= n
0055             error('sltoolbox:sizmismatch', ...
0056                 'The nums are inconsistent with the number of samples');
0057         end
0058         
0059         c = length(nums);
0060         if nargin == 2 || ~iscell(varargin{2})
0061             plotsyms = default_plotsyms(c);
0062             pidx = 2;
0063         else
0064             plotsyms = varargin{2};
0065             pidx = 3;
0066         end
0067         
0068     end
0069         
0070     if pidx <= length(varargin)
0071         plotprops = varargin(pidx:end);
0072     end
0073         
0074 end
0075 
0076 
0077 %% Argument Preparation
0078 
0079 if ~multiclass
0080     if d == 2        
0081         args = {X(1,:), X(2,:), plotsyms{1}};
0082     elseif d == 3
0083         args = {X(1,:), X(2,:), X(3,:), plotsyms{1}};
0084     end            
0085 else
0086     [sinds, einds] = slnums2bounds(nums);
0087     ck = 0;
0088     
0089     if d == 2
0090         args = cell(3, sum(nums > 0));
0091         for k = 1 : c
0092             if nums(k) > 0
0093                 ck = ck + 1;
0094                 si = sinds(k); ei = einds(k);
0095                 args{1, ck} = X(1, si:ei);
0096                 args{2, ck} = X(2, si:ei);
0097                 args{3, ck} = plotsyms{k};
0098             end                        
0099         end
0100         
0101     elseif d == 3
0102         args = cell(4, sum(nums > 0));
0103         for k = 1 : c
0104             if nums(k) > 0
0105                 ck = ck + 1;
0106                 si = sinds(k); ei = einds(k);
0107                 args{1, ck} = X(1, si:ei);
0108                 args{2, ck} = X(2, si:ei);
0109                 args{3, ck} = X(3, si:ei);
0110                 args{4, ck} = plotsyms{k};
0111             end
0112         end
0113         
0114     end
0115     args = reshape(args, [1, numel(args)]);
0116     
0117 end
0118 
0119 %% Plot
0120 
0121 if nargout == 0
0122     if d == 2
0123         plot(args{:}, plotprops{:});
0124     elseif d == 3
0125         plot3(args{:}, plotprops{:});
0126     end
0127 else
0128     if d == 2
0129         h = plot(args{:}, plotprops{:});
0130     elseif d == 3
0131         h = plot3(args{:}, plotprops{:});
0132     end
0133 end
0134 
0135 
0136 %% Auxiliary functions
0137 
0138 function plotsyms = default_plotsyms(n)
0139 
0140 ps0 = {'b.', 'g.', 'r.', 'c.', 'm.', 'y.', 'k.'};
0141 n0 = length(ps0);
0142 
0143 inds = mod(0:n-1, n0) + 1;
0144 plotsyms = ps0(inds);
0145 
0146

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

Contact us at files@mathworks.com