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 edl_buildiidxdict
Home > sltoolbox > ExpDL > edl_buildiidxdict.m

edl_buildiidxdict

PURPOSE ^

EDL_BUILDIIDXDICT Builds a dictionary using internal index

SYNOPSIS ^

function Dict = edl_buildiidxdict(S, idxfn)

DESCRIPTION ^

EDL_BUILDIIDXDICT Builds a dictionary using internal index

 $ Syntax $
   - Dict = edl_buildiidxdict(S, idxfn)

 $ Arguments $
   - S:        a struct array on which the dictionary is built
   - idxfn:    the field name of the internal index 
               (default = 'internal_index')
   - Dict:     the built dictionary
               a cell array, indexed by internal_index

 $ Remarks $
   - The length of the cell array (dict) will be equal to the maximum
     internal index in S.
   - In S, different elements should have different internal indices.
   - For the index corresponding to no element, the corresponding cells
     are empty.
   - The dictionary will not automatically keep track of the change of
     S. If S is changed, the dictonary should be rebuilt in order to
     reflect the updates.

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

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:

SOURCE CODE ^

0001 function Dict = edl_buildiidxdict(S, idxfn)
0002 %EDL_BUILDIIDXDICT Builds a dictionary using internal index
0003 %
0004 % $ Syntax $
0005 %   - Dict = edl_buildiidxdict(S, idxfn)
0006 %
0007 % $ Arguments $
0008 %   - S:        a struct array on which the dictionary is built
0009 %   - idxfn:    the field name of the internal index
0010 %               (default = 'internal_index')
0011 %   - Dict:     the built dictionary
0012 %               a cell array, indexed by internal_index
0013 %
0014 % $ Remarks $
0015 %   - The length of the cell array (dict) will be equal to the maximum
0016 %     internal index in S.
0017 %   - In S, different elements should have different internal indices.
0018 %   - For the index corresponding to no element, the corresponding cells
0019 %     are empty.
0020 %   - The dictionary will not automatically keep track of the change of
0021 %     S. If S is changed, the dictonary should be rebuilt in order to
0022 %     reflect the updates.
0023 %
0024 % $ History $
0025 %   - Created by Dahua Lin, on Aug 15, 2006
0026 %
0027 
0028 %% parse and verify input arguments
0029 
0030 if ~isstruct(S)
0031     error('sltoolbox:invalidarg', ...
0032         'The S should be a struct');
0033 end
0034 
0035 if nargin < 2 || isempty(idxfn)
0036     idxfn = 'internal_index';
0037 end
0038 
0039 if ~isfield(S, idxfn)
0040     error('sltoolbox:invalidarg', ...
0041         'The S have no specified internal index field');
0042 end
0043 
0044 %% Build dictionary
0045 
0046 % gather the internal indices
0047 n = numel(S);
0048 inds = zeros(n, 1);
0049 for i = 1 : n
0050     idx = S(i).(idxfn);
0051     if ischar(idx)
0052         idx = str2double(idx);
0053     end
0054     inds(i) = idx;
0055 end
0056 
0057 % construct dictionary
0058 m = max(inds);
0059 
0060 Dict = cell(m, 1);
0061 
0062 for i = 1 : n
0063     idx = inds(i);
0064     if ~isempty(Dict{idx})
0065         error('sltoolbox:rterror', ...
0066             'Repeated index %d is encountered', idx);
0067     end
0068     Dict{idx} = S(i);        
0069 end
0070

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

Contact us at files@mathworks.com