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

dataset

PURPOSE ^

DATASET Constructs a dataset object (conform to DSDML)

SYNOPSIS ^

function DS = dataset(varargin)

DESCRIPTION ^

DATASET Constructs a dataset object (conform to DSDML)

 $ Syntax $
   - DS = dataset()
   - DS = dataset(attribs)
   - DS = dataset(attrname1, attrvalue1, ...)
   - DS = dataset(filename)
   - DS = dataset('from:fns', name, format, fns, labels);

 $ Arguments $
   - DS:           the dataset constructed
   - attribs:      the struct of the attributes
   - filename:     the DSDML file describing the data set.

 $ Description $
   - DS = dataset() constructs an empty data set with default attributes.
   
   - DS = dataset(attribs) constructs an empty data set with some 
     attributes specified in the struct attribs.

   - DS = dataset(attrname1, attrvalue1, ...) constructs an empty 
     dataset with some attributes specified in the attribute list.

   - DS = dataset(filename) constructs the dataset by loading it from
     a DSDML file.

   - DS = dataset('from:fns', name, format, fns, labels) constructs the 
     dataset by using construct_dataset_fns.m

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
  • slimgsetprep SLIMGSETPREP organizes the images in a MATLAB friendly way

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function DS = dataset(varargin)
0002 %DATASET Constructs a dataset object (conform to DSDML)
0003 %
0004 % $ Syntax $
0005 %   - DS = dataset()
0006 %   - DS = dataset(attribs)
0007 %   - DS = dataset(attrname1, attrvalue1, ...)
0008 %   - DS = dataset(filename)
0009 %   - DS = dataset('from:fns', name, format, fns, labels);
0010 %
0011 % $ Arguments $
0012 %   - DS:           the dataset constructed
0013 %   - attribs:      the struct of the attributes
0014 %   - filename:     the DSDML file describing the data set.
0015 %
0016 % $ Description $
0017 %   - DS = dataset() constructs an empty data set with default attributes.
0018 %
0019 %   - DS = dataset(attribs) constructs an empty data set with some
0020 %     attributes specified in the struct attribs.
0021 %
0022 %   - DS = dataset(attrname1, attrvalue1, ...) constructs an empty
0023 %     dataset with some attributes specified in the attribute list.
0024 %
0025 %   - DS = dataset(filename) constructs the dataset by loading it from
0026 %     a DSDML file.
0027 %
0028 %   - DS = dataset('from:fns', name, format, fns, labels) constructs the
0029 %     dataset by using construct_dataset_fns.m
0030 %
0031 % $ History $
0032 %   - Created by Dahua Lin on Jul 23rd, 2006
0033 %
0034 
0035 
0036 %% Parse the input arguments
0037 
0038 cway = '';
0039 if ~isempty(varargin)
0040     if length(varargin) == 1
0041         if ischar(varargin{1})
0042             cway = 'file';
0043             filename = varargin{1};
0044         elseif isstruct(varargin{1})
0045             cway = 'attr.struct';
0046             attrs = varargin{1};
0047         else
0048             error('dsdml:invalidarg', ...
0049                 'Invalid input arguments for dataset construction');
0050         end
0051     else
0052         switch varargin{1}
0053             case 'from:fns'
0054                 cway = 'from:fns';
0055                 params = varargin(2:end);
0056             otherwise
0057                 cway = 'attr.list';
0058                 attrs = varargin;
0059         end        
0060     end
0061 end
0062                     
0063 
0064 %% Initialize the default empty dataset
0065 
0066 DS.version = '1.00';
0067 DS.name = [];
0068 DS.unittype = [];
0069 DS.format = [];
0070 DS.author = [];
0071 DS.description = [];
0072 DS.attribs = [];
0073 DS.units = [];
0074 
0075 DS = class(DS, 'dataset');
0076 
0077 %% Further construction
0078 
0079 switch cway
0080     case 'file'        
0081         DS = readfile(DS, filename);
0082         
0083     case 'attr.struct'
0084         attrnames = fieldnames(attrs);
0085         nattrs = length(attrnames);
0086         attrvalues = cell(nattrs, 1);
0087         for i = 1 : nattrs
0088             v = attrs.(attrnames{i});
0089             attrvalues{i} = v;
0090         end
0091         DS = dataset_setattribs(DS, nattrs, attrnames, attrvalues);
0092         
0093     case 'attr.list'
0094         len = length(attrs);
0095         if mod(len, 2) ~= 0
0096             error('dsdml:invalidarg', ...
0097                 'The length of the input argument list should be even when it specifies attribute list');
0098         end
0099         nattrs = len / 2;
0100         attrnames = attrs(1:2:end)';
0101         attrvalues = attrs(2:2:end)';
0102         DS = dataset_setattribs(DS, nattrs, attrnames, attrvalues);       
0103         
0104     case 'from:fns'
0105         DS = construct_dataset_filenames(DS, params{:});
0106 end
0107 
0108 
0109 %%  Sub functions
0110 
0111 function DS = dataset_setattribs(DS, n, attrnames, attrvalues)
0112 
0113 % check values
0114 for i = 1 : n
0115     if ~ischar(attrvalues{i})
0116         error('dsdml:invalidarg', ...
0117             'The %d attribute value is not a char string', i);
0118     end
0119 end
0120 
0121 % set values
0122 S = DS;
0123 
0124 for i = 1 : n
0125     aname = attrnames{i};
0126     aval = attrvalues{i};
0127     
0128     if isfield(S, aname)
0129         S.(aname) = aval;
0130     else
0131         S.attribs.(aname) = aval;
0132     end
0133     
0134 end
0135 
0136 DS = S;
0137 
0138

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

Contact us at files@mathworks.com