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 sllabelinds
Home > sltoolbox > utils > sllabelinds.m

sllabelinds

PURPOSE ^

SLLABELINDS Extract indices corresponding to specified labels

SYNOPSIS ^

function Inds = sllabelinds(labels, labelset)

DESCRIPTION ^

SLLABELINDS Extract indices corresponding to specified labels

 $ Syntax $
   - Inds = sllabelinds(labels, labelset)

 $ Arguments $
   - labels:       The labels of samples
   - labelset:     The set of labels whose indices to be extracted
   - Inds:         The cell array of indices extracted for labelset

 $ Description $
   - Inds = sllabelinds(labels, labelset) extracts the indices 
     corresponding to the labels specified in labelset. Suppose the
     labelset is given by [l1, l2, ...], then Inds would be like
     {[i11, i12, ...], [i21, i22, ...], ...}, where [i11, i12, ...] is
     a row vector of indices corresponding to l1, so that 
     labels(i11) = labels(i12) = ... = l1.
   
 $ History $
   - Created by Dahua Lin, on Aug 31, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slcount SLCOUNT Count the number of sum entities
  • slnums2bounds SLNUMS2BOUNDS Compute the index-boundaries from section sizes
This function is called by:
  • slkmeans SLKMEANS Performs K-Means Clustering on samples
  • sllabeledsum SLLABELEDSUM Sums the numbers according to labels

SOURCE CODE ^

0001 function Inds = sllabelinds(labels, labelset)
0002 %SLLABELINDS Extract indices corresponding to specified labels
0003 %
0004 % $ Syntax $
0005 %   - Inds = sllabelinds(labels, labelset)
0006 %
0007 % $ Arguments $
0008 %   - labels:       The labels of samples
0009 %   - labelset:     The set of labels whose indices to be extracted
0010 %   - Inds:         The cell array of indices extracted for labelset
0011 %
0012 % $ Description $
0013 %   - Inds = sllabelinds(labels, labelset) extracts the indices
0014 %     corresponding to the labels specified in labelset. Suppose the
0015 %     labelset is given by [l1, l2, ...], then Inds would be like
0016 %     {[i11, i12, ...], [i21, i22, ...], ...}, where [i11, i12, ...] is
0017 %     a row vector of indices corresponding to l1, so that
0018 %     labels(i11) = labels(i12) = ... = l1.
0019 %
0020 % $ History $
0021 %   - Created by Dahua Lin, on Aug 31, 2006
0022 %
0023 
0024 %% parse and verify input
0025 
0026 if ~isvector(labels) || ~isnumeric(labels)
0027     error('sltoolbox:invalidarg', ...
0028         'labels should be a numeric vector');
0029 end
0030 
0031 if size(labels, 1) ~= 1
0032     labels = labels(:)';
0033 end
0034 
0035 %% re-arrange
0036 
0037 [labels, si] = sort(labels, 2, 'ascend');
0038 [nums, labelfound] = slcount(labels);
0039 [sinds, einds] = slnums2bounds(nums);
0040 [sfound, smap] = ismember(labelset, labelfound);
0041 
0042 %% extract
0043 
0044 c = length(labelset);
0045 Inds = cell(1, c);
0046 for i = 1 : c
0047     if sfound(i)
0048         mi = smap(i);
0049         curinds = si(sinds(mi):einds(mi));
0050         Inds{i} = curinds;
0051     else
0052         Inds{i} = [];
0053     end
0054 end
0055 
0056 
0057 
0058 
0059 
0060 
0061

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

Contact us at files@mathworks.com