Daniel@0: function sData = som_data_struct(D, varargin) Daniel@0: Daniel@0: %SOM_DATA_STRUCT Create a data struct. Daniel@0: % Daniel@0: % sData = som_data_struct(D, [argID, value, ...]) Daniel@0: % Daniel@0: % sData = som_data_struct(D); Daniel@0: % sData = som_data_struct(D,'name','my_data','labels',labs); Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional): Daniel@0: % D (matrix) data matrix, size dlen x dim Daniel@0: % [argID, (string) See below. These are given as argID, value pairs. Daniel@0: % value] (varies) Daniel@0: % Daniel@0: % sData (struct) created data struct Daniel@0: % Daniel@0: % Here are the argument IDs and corresponding values: Daniel@0: % 'labels' (string array / cellstr) labels for each data vector, Daniel@0: % length=dlen Daniel@0: % 'name' (string) data name Daniel@0: % 'comp_names' (string array / cellstr) component names, size dim x 1 Daniel@0: % 'comp_norm' (cell array) normalization operations for each Daniel@0: % component, size dim x 1. Each cell is either empty, Daniel@0: % or a cell array of normalization structs. Daniel@0: % Daniel@0: % For more help, try 'type som_data_struct' or check out online documentation. Daniel@0: % See also SOM_SET, SOM_INFO, SOM_MAP_STRUCT. Daniel@0: Daniel@0: %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Daniel@0: % som_data_struct Daniel@0: % Daniel@0: % PURPOSE Daniel@0: % Daniel@0: % Creates a data structure. Daniel@0: % Daniel@0: % SYNTAX Daniel@0: % Daniel@0: % sD = som_data_struct(D); Daniel@0: % sD = som_data_struct(...,'argID',value,...); Daniel@0: % Daniel@0: % DESCRIPTION Daniel@0: % Daniel@0: % Creates a data struct. The struct contains, in addition to the data Daniel@0: % matrix, component names, normalization operations for the components, Daniel@0: % labels for each vector, and a name for the whole data set. All of these Daniel@0: % can be given in the optional arguments of the function. If left Daniel@0: % unspecified, they are given default values. Daniel@0: % Daniel@0: % Field Type Size / default value Daniel@0: % ------------------------------------------------------------------------ Daniel@0: % .type (string) 'som_data' Daniel@0: % .data (matrix) size dlen x dim Daniel@0: % .name (string) 'unnamed' Daniel@0: % .labels (cellstr) size dlen x m, {''; ''; ... ''} Daniel@0: % .comp_names (cellstr) size dim x 1, {'Variable1', 'Variable2', ...} Daniel@0: % .comp_norm (cell array) size dim x 1, {[], [], ... []} Daniel@0: % .label_names (cellstr) size m x 1, [] Daniel@0: % Daniel@0: % '.type' field is the struct identifier. Do not change it. Daniel@0: % '.data' field is the data matrix, each row is one data vector Daniel@0: % '.name' field is the identifier for the whole data struct Daniel@0: % '.labels' field contains the labels for each of the vectors. The ith Daniel@0: % of '.labels' contains the labels for ith data vector. Note that Daniel@0: % if some vectors have more labels than others, the others are Daniel@0: % are given empty labels ('') to pad the '.labels' array up. Daniel@0: % '.comp_names' field contains the names of the vector components Daniel@0: % '.comp_norm' field contains normalization information for each Daniel@0: % component. Each cell of '.comp_norm' is itself a cell array of Daniel@0: % normalization structs. If no normalizations are performed for Daniel@0: % the particular component, the cell is empty ([]). Daniel@0: % '.label_names' is similar to .comp_names field holding the names for Daniel@0: % each data label column Daniel@0: % Daniel@0: % REQUIRED INPUT ARGUMENTS Daniel@0: % Daniel@0: % D (matrix) The data matrix, size dlen x dim. The data matrix may Daniel@0: % contain unknown values, indicated by NaNs. Daniel@0: % Daniel@0: % OPTIONAL INPUT ARGUMENTS Daniel@0: % Daniel@0: % argID (string) Argument identifier string (see below). Daniel@0: % value (varies) Value for the argument (see below). Daniel@0: % Daniel@0: % The optional arguments can be given as 'argID',value -pairs as Daniel@0: % listed below. If an argument is given value multiple times, the Daniel@0: % last one is used. Daniel@0: % Daniel@0: % 'labels' (string array / cellstr) labels for each data vector, Daniel@0: % size dlen x m Daniel@0: % 'name' (string) data name Daniel@0: % 'comp_names' (string array / cellstr) component names, size dim x 1 Daniel@0: % 'comp_norm' (cell array) normalization operations for each Daniel@0: % component, size dim x 1. Each cell is either empty, Daniel@0: % or a cell array of normalization structs. Daniel@0: % 'label_names'(string array / cellstr) label names, size m x 1 Daniel@0: % Daniel@0: % OUTPUT ARGUMENTS Daniel@0: % Daniel@0: % sD (struct) the data struct Daniel@0: % Daniel@0: % EXAMPLES Daniel@0: % Daniel@0: % Simplest case: Daniel@0: % D = rand(8, 3); % 8 3-dimensional vectors Daniel@0: % sD = som_data_struct(D); Daniel@0: % Daniel@0: % With optional arguments, the other fields can be given values: Daniel@0: % labs = cell(8, 1); labs{1, 1} = 'first_label'; Daniel@0: % cnames = {'first'; 'second'; 'third'}; Daniel@0: % Daniel@0: % sD = som_data_struct(D,'labels',labs,'name','a data struct'); Daniel@0: % sD = som_data_struct(D,'comp_names',cnames); Daniel@0: % Daniel@0: % SEE ALSO Daniel@0: % Daniel@0: % som_set Set values and create SOM Toolbox structs. Daniel@0: % som_map_struct Create a map struct. Daniel@0: Daniel@0: % Copyright (c) 1997-2000 by the SOM toolbox programming team. Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 1.0beta ecco 071197 Daniel@0: % Version 2.0beta juuso 101199 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: % data Daniel@0: [dlen dim] = size(D); Daniel@0: Daniel@0: % default values Daniel@0: if ~isempty(inputname(1)), name = inputname(1); Daniel@0: else name = 'unnamed'; end Daniel@0: labels = cell(dlen,1); Daniel@0: labels(1:dlen) = {''}; Daniel@0: %for i=1:dlen, labels{i} = ''; end Daniel@0: comp_names = cell(dim,1); Daniel@0: for i = 1:dim, comp_names{i} = sprintf('Variable%d', i); end Daniel@0: comp_norm = cell(dim,1); Daniel@0: label_names = []; Daniel@0: Daniel@0: % varargin Daniel@0: i=1; Daniel@0: while i<=length(varargin), Daniel@0: argok = 1; Daniel@0: if ischar(varargin{i}), Daniel@0: switch varargin{i}, Daniel@0: % argument IDs Daniel@0: case 'comp_names', i=i+1; comp_names = varargin{i}; Daniel@0: case 'labels', i=i+1; labels = varargin{i}; Daniel@0: case 'name', i=i+1; name = varargin{i}; Daniel@0: case 'comp_norm', i=i+1; comp_norm = varargin{i}; Daniel@0: case 'label_names',i=i+1; label_names = varargin{i}; Daniel@0: otherwise argok=0; Daniel@0: end Daniel@0: else Daniel@0: argok = 0; Daniel@0: end Daniel@0: if ~argok, Daniel@0: disp(['(som_data_struct) Ignoring invalid argument #' num2str(i+1)]); Daniel@0: end Daniel@0: i = i+1; Daniel@0: end Daniel@0: Daniel@0: % create struct Daniel@0: sData = som_set('som_data','data',D,'labels',labels,... Daniel@0: 'name',name,'comp_names',comp_names,... Daniel@0: 'comp_norm',comp_norm,'label_names',label_names); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: Daniel@0: