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

sldrawlabeledpts

PURPOSE ^

SLDRAWLABELEDPTS Draws Labeled 2D or 3D points

SYNOPSIS ^

function h = sldrawlabeledpts(X, labels, labelset, plotsyms, varargin)

DESCRIPTION ^

SLDRAWLABELEDPTS Draws Labeled 2D or 3D points

 $ Syntax $
   - sldrawlabeledpts(X, labels)
   - sldrawlabeledpts(X, labels, labelset)
   - sldrawlabeledpts(X, labels, labelset, plotsyms, ...)
   - h = sldrawlabeledpts(...)

 $ Arguments $
   - X:            the sample matrix (2 x n or 3 x n)
   - labels:       the row vector of labels of the samples
   - labelset:     the set of used labels
   - plotsyms:     the plotting symbols for the labels
   - h:            the handles of the plots

 $ Description $
   - sldrawlabeledpts(X, labels) draws a set of 2D or 3D samples 
     with different labels using different plotting symbols.

   - sldrawlabeledpts(X, labels, labelset) also specifies the 
     set of labels that may be used.

   - sldrawlabeledpts(X, labels, labelset, plotsyms, ...) specifies
     the plotting symbols or even extra plotting properties.

   - h = sldrawlabeledpts(...) returns the vector of handles to the
     plottings.

 $ Remarks $
   - If labelset is not specified, then it will be automatically 
     generated by applying function unique on labels. The plotsyms
     will be used following the order in labelset.
   
   - The points with labels not in labelset will not be plotted.

   - The implementation is based on sldrawpts.

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

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • sldrawpts SLDRAWPTS Draws a set of sample points on axes
This function is called by:

SOURCE CODE ^

0001 function h = sldrawlabeledpts(X, labels, labelset, plotsyms, varargin)
0002 %SLDRAWLABELEDPTS Draws Labeled 2D or 3D points
0003 %
0004 % $ Syntax $
0005 %   - sldrawlabeledpts(X, labels)
0006 %   - sldrawlabeledpts(X, labels, labelset)
0007 %   - sldrawlabeledpts(X, labels, labelset, plotsyms, ...)
0008 %   - h = sldrawlabeledpts(...)
0009 %
0010 % $ Arguments $
0011 %   - X:            the sample matrix (2 x n or 3 x n)
0012 %   - labels:       the row vector of labels of the samples
0013 %   - labelset:     the set of used labels
0014 %   - plotsyms:     the plotting symbols for the labels
0015 %   - h:            the handles of the plots
0016 %
0017 % $ Description $
0018 %   - sldrawlabeledpts(X, labels) draws a set of 2D or 3D samples
0019 %     with different labels using different plotting symbols.
0020 %
0021 %   - sldrawlabeledpts(X, labels, labelset) also specifies the
0022 %     set of labels that may be used.
0023 %
0024 %   - sldrawlabeledpts(X, labels, labelset, plotsyms, ...) specifies
0025 %     the plotting symbols or even extra plotting properties.
0026 %
0027 %   - h = sldrawlabeledpts(...) returns the vector of handles to the
0028 %     plottings.
0029 %
0030 % $ Remarks $
0031 %   - If labelset is not specified, then it will be automatically
0032 %     generated by applying function unique on labels. The plotsyms
0033 %     will be used following the order in labelset.
0034 %
0035 %   - The points with labels not in labelset will not be plotted.
0036 %
0037 %   - The implementation is based on sldrawpts.
0038 %
0039 % $ History $
0040 %   - Created by Dahua Lin, on Aug 28, 2006
0041 %
0042 
0043 %% Parse and verify input arguments
0044 
0045 if nargin < 2
0046     raise_lackinput('sldrawlabeledpts', 2);
0047 end
0048 
0049 if ~isnumeric(X) || ndims(X) ~= 2
0050     error('sltoolbox:invalidarg', ...
0051         'X should be a 2D numeric matrix');
0052 end
0053 
0054 n = size(X, 2);
0055 
0056 if ~isequal(size(labels), [1 n])
0057     error('sltoolbox:sizmismatch', ...
0058         'The labels should be a 1 x n row vector');
0059 end
0060 
0061 if nargin < 3 || isempty(labelset)
0062     labelset = unique(labels);
0063 end
0064 
0065 if nargin < 4 || isempty(plotsyms)
0066     plotsyms = [];
0067 end
0068 
0069 %% Rearrange samples
0070 
0071 K = length(labelset);
0072 nums = zeros(1, K);
0073 inds = cell(1, K);
0074 
0075 for i = 1 : K    
0076     inds{i} = find(labels == labelset(i));    
0077     nums(i) = length(inds{i});
0078 end
0079 
0080 inds = horzcat(inds{:});
0081 X = X(:, inds);
0082 
0083 %% Plot
0084 
0085 if nargout == 0
0086     if isempty(plotsyms)
0087         sldrawpts(X, nums, varargin{:});
0088     else
0089         sldrawpts(X, nums, plotsyms, varargin{:});
0090     end
0091 else
0092     if isempty(plotsyms)
0093         h = sldrawpts(X, nums, varargin{:});
0094     else
0095         h = sldrawpts(X, nums, plotsyms, varargin{:});
0096     end
0097 end
0098 
0099 
0100 
0101 
0102 
0103 
0104    
0105 
0106     
0107 
0108 
0109 
0110 
0111

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

Contact us at files@mathworks.com