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 get

get

PURPOSE ^

GET gets the properties of the dataset

SYNOPSIS ^

function R = get(DS, props)

DESCRIPTION ^

GET gets the properties of the dataset

 $ Syntax $
   - R = get(DS, propname)
   - R = get(DS, propname cell array)

 $ Description $   
   - R = get(DS, propname) gets a property value with its name specified
     by propname

   - R = get(DS, propname cell array) gets a set of properties with the
     names given in a cell array. Consequently, the property values are
     returns through a cell array of the same size.

 $ Remarks $
   - The 
 $ History $
   - Created by Dahua Lin on Jul 23rd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • display DISPLAY displays the dataset fields.
  • subsref SUBSREF Get the properties by subscription
  • subsref SUBSREF Get the properties by subscription

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function R = get(DS, props)
0002 %GET gets the properties of the dataset
0003 %
0004 % $ Syntax $
0005 %   - R = get(DS, propname)
0006 %   - R = get(DS, propname cell array)
0007 %
0008 % $ Description $
0009 %   - R = get(DS, propname) gets a property value with its name specified
0010 %     by propname
0011 %
0012 %   - R = get(DS, propname cell array) gets a set of properties with the
0013 %     names given in a cell array. Consequently, the property values are
0014 %     returns through a cell array of the same size.
0015 %
0016 % $ Remarks $
0017 %   - The
0018 % $ History $
0019 %   - Created by Dahua Lin on Jul 23rd, 2006
0020 %
0021 
0022 %% Skeleton
0023 
0024 if ischar(props)    
0025     S = struct(DS);
0026     R = getprop(S, props);
0027     
0028 elseif iscell(props)
0029     S = struct(DS);
0030     R = cell(size(props));
0031     n = numel(R);
0032     for i = 1 : n
0033         if ~ischar(props{i})
0034             error('dsdml:invalidarg', ...
0035                 'The property name should be a char string');
0036         end
0037         R{i} = getprop(S, props{i});
0038     end
0039     
0040 else
0041     error('dsdml:invalidarg', ...
0042         'The props should be a property name or a cell of property names');
0043 end
0044 
0045 
0046 %% Property getting function
0047 
0048 function R = getprop(S, propname)
0049 
0050 if isfield(S, propname)
0051     R = S.(propname);
0052 elseif ~isempty(S.attribs) && isfield(S.attribs, propname)
0053     R = S.attribs.(propname);
0054 else
0055     switch(propname)
0056         case 'numsamples'
0057             R = getnumsamples(S);
0058         case 'numgroups'
0059             R = getnumgroups(S);
0060         case 'numunits'
0061             R = length(S.units);
0062             
0063         case 'samples'
0064             R = getsamples(S);
0065         case 'groups'
0066             R = getgroups(S);
0067         case 'class_ids'
0068             R = getclass_ids(S);
0069         case 'filenames'
0070             R = getfilenames(S);
0071         case 'nums'
0072             R = getnums(S);
0073             
0074         case 'numspergrp'
0075             R = getnumspergrp(S);
0076         case 'grpnums'
0077             R = getgrpnums(S);
0078         case 'grpclass_ids'
0079             R = getgrpclass_ids(S);
0080             
0081         otherwise
0082             error('dsdml:invalidarg', ...
0083                 'Invalid property name of the dataset: %s', propname);
0084     end
0085 end
0086 
0087 
0088 %% Specific property getting functions
0089 
0090 function R = getnumsamples(S)
0091 
0092 switch S.unittype
0093     case 'Sample'
0094         R = length(S.units);
0095     case 'SampleGroup'
0096         R = 0;
0097         ng = length(S.units);
0098         for i = 1 : ng
0099             R = R + length(S.units(i).samples);
0100         end
0101     otherwise
0102         invalid_utype(S);
0103 end
0104 
0105 
0106 function R = getnumgroups(S)
0107 
0108 switch S.unittype
0109     case {'Sample', 'SampleGroup'}
0110         R = length(S.units);
0111     otherwise
0112         invalid_utype(S);
0113 end
0114 
0115 
0116 function R = getsamples(S)
0117 
0118 switch S.unittype
0119     case 'Sample'
0120         R = S.units;
0121     case 'SampleGroup'
0122         R = vertcat(S.units.samples);
0123     otherwise
0124         invalid_utype(S);
0125 end
0126 
0127 
0128 function R = getgroups(S)
0129 
0130 switch S.unittype
0131     case 'Sample'
0132         n = length(S.units);
0133         U = S.units;
0134         R = struct(...
0135             'class_id', cell(n, 1), ...
0136             'samples', cell(n, 1), ...
0137             'attribs', cell(n, 1));
0138         for i = 1 : n
0139             R(i).class_id = U(i).class_id;
0140             R(i).samples = U(i);
0141         end
0142     case 'SampleGroup'
0143         R = S.units;
0144     otherwise
0145         invalid_utype(S);
0146 end
0147 
0148 
0149 function R = getclass_ids(S)
0150 
0151 switch(S.unittype)
0152     case 'Sample'
0153         n = length(S.units);
0154         R = zeros(n, 1);
0155         for i = 1 : n
0156             R(i) = S.units(i).class_id;
0157         end
0158     case 'SampleGroup'
0159         n = getnumsamples(S);
0160         R = zeros(n, 1);
0161         c = 0;
0162         ng = length(S.units);
0163         for i = 1 : ng
0164             ns = length(S.units(i).samples);
0165             R(c+1:c+ns) = S.units(i).class_id;
0166             c = c + ns;
0167         end
0168     otherwise
0169         invalid_utype(S);
0170 end
0171 
0172 
0173 function R = getfilenames(S)
0174 
0175 switch(S.unittype)
0176     case 'Sample'
0177         n = length(S.units);
0178         R = cell(n, 1);
0179         for i = 1 : n
0180             R{i} = S.units(i).filename;
0181         end
0182     case 'SampleGroup'
0183         n = getnumsamples(S);
0184         R = cell(n, 1);
0185         c = 0;
0186         ng = length(S.units);
0187         for i = 1 : ng
0188             ns = length(S.units(i).samples);
0189             [R{c+1:c+ns}] = deal(S.units(i).samples.filename);
0190             c = c + ns;
0191         end
0192     otherwise
0193         invalid_utype(S);
0194 end
0195 
0196 
0197 function R = getnums(S)
0198 
0199 R = countnums(getclass_ids(S));
0200 
0201 
0202 
0203 function R = getnumspergrp(S)
0204 
0205 switch (S.unittype)
0206     case 'Sample'
0207         n = length(S.units);
0208         R = ones(n, 1);
0209         
0210     case 'SampleGroup'
0211         n = length(S.units);
0212         R = zeros(n, 1);
0213         for i = 1 : n
0214             R(i) = length(S.units(i).samples);
0215         end
0216         
0217     otherwise
0218         invalid_utype(S);
0219 end
0220 
0221 
0222 function R = getgrpnums(S)
0223 
0224 R = countnums(getgrpclass_ids(S));
0225         
0226 
0227 function R = getgrpclass_ids(S)
0228 
0229 switch (S.unittype)
0230     case {'Sample', 'SampleGroup'}
0231         n = length(S.units);
0232         R = zeros(n, 1);
0233         for i = 1 : n
0234             R(i) = S.units(i).class_id;
0235         end
0236         
0237     otherwise
0238         invalid_utype(S);
0239 end                                    
0240 
0241 
0242 
0243 %% Auxiliary functions
0244 
0245 function invalid_utype(S)
0246 
0247 error('dsdml:invalidunittype', ...
0248             'Invalid unit type: %s', S.unittype);
0249 
0250 
0251 function nums = countnums(A)
0252 
0253 A = A(:);
0254 difs = diff(A);
0255 n = length(A);
0256 nums = [0; find(difs ~= 0); n];
0257 nums = diff(nums);
0258 
0259 
0260 
0261 
0262 
0263     
0264 
0265 
0266 
0267 
0268

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

Contact us at files@mathworks.com