annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_data_struct.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function sData = som_data_struct(D, varargin)
wolffd@0 2
wolffd@0 3 %SOM_DATA_STRUCT Create a data struct.
wolffd@0 4 %
wolffd@0 5 % sData = som_data_struct(D, [argID, value, ...])
wolffd@0 6 %
wolffd@0 7 % sData = som_data_struct(D);
wolffd@0 8 % sData = som_data_struct(D,'name','my_data','labels',labs);
wolffd@0 9 %
wolffd@0 10 % Input and output arguments ([]'s are optional):
wolffd@0 11 % D (matrix) data matrix, size dlen x dim
wolffd@0 12 % [argID, (string) See below. These are given as argID, value pairs.
wolffd@0 13 % value] (varies)
wolffd@0 14 %
wolffd@0 15 % sData (struct) created data struct
wolffd@0 16 %
wolffd@0 17 % Here are the argument IDs and corresponding values:
wolffd@0 18 % 'labels' (string array / cellstr) labels for each data vector,
wolffd@0 19 % length=dlen
wolffd@0 20 % 'name' (string) data name
wolffd@0 21 % 'comp_names' (string array / cellstr) component names, size dim x 1
wolffd@0 22 % 'comp_norm' (cell array) normalization operations for each
wolffd@0 23 % component, size dim x 1. Each cell is either empty,
wolffd@0 24 % or a cell array of normalization structs.
wolffd@0 25 %
wolffd@0 26 % For more help, try 'type som_data_struct' or check out online documentation.
wolffd@0 27 % See also SOM_SET, SOM_INFO, SOM_MAP_STRUCT.
wolffd@0 28
wolffd@0 29 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 30 %
wolffd@0 31 % som_data_struct
wolffd@0 32 %
wolffd@0 33 % PURPOSE
wolffd@0 34 %
wolffd@0 35 % Creates a data structure.
wolffd@0 36 %
wolffd@0 37 % SYNTAX
wolffd@0 38 %
wolffd@0 39 % sD = som_data_struct(D);
wolffd@0 40 % sD = som_data_struct(...,'argID',value,...);
wolffd@0 41 %
wolffd@0 42 % DESCRIPTION
wolffd@0 43 %
wolffd@0 44 % Creates a data struct. The struct contains, in addition to the data
wolffd@0 45 % matrix, component names, normalization operations for the components,
wolffd@0 46 % labels for each vector, and a name for the whole data set. All of these
wolffd@0 47 % can be given in the optional arguments of the function. If left
wolffd@0 48 % unspecified, they are given default values.
wolffd@0 49 %
wolffd@0 50 % Field Type Size / default value
wolffd@0 51 % ------------------------------------------------------------------------
wolffd@0 52 % .type (string) 'som_data'
wolffd@0 53 % .data (matrix) size dlen x dim
wolffd@0 54 % .name (string) 'unnamed'
wolffd@0 55 % .labels (cellstr) size dlen x m, {''; ''; ... ''}
wolffd@0 56 % .comp_names (cellstr) size dim x 1, {'Variable1', 'Variable2', ...}
wolffd@0 57 % .comp_norm (cell array) size dim x 1, {[], [], ... []}
wolffd@0 58 % .label_names (cellstr) size m x 1, []
wolffd@0 59 %
wolffd@0 60 % '.type' field is the struct identifier. Do not change it.
wolffd@0 61 % '.data' field is the data matrix, each row is one data vector
wolffd@0 62 % '.name' field is the identifier for the whole data struct
wolffd@0 63 % '.labels' field contains the labels for each of the vectors. The ith
wolffd@0 64 % of '.labels' contains the labels for ith data vector. Note that
wolffd@0 65 % if some vectors have more labels than others, the others are
wolffd@0 66 % are given empty labels ('') to pad the '.labels' array up.
wolffd@0 67 % '.comp_names' field contains the names of the vector components
wolffd@0 68 % '.comp_norm' field contains normalization information for each
wolffd@0 69 % component. Each cell of '.comp_norm' is itself a cell array of
wolffd@0 70 % normalization structs. If no normalizations are performed for
wolffd@0 71 % the particular component, the cell is empty ([]).
wolffd@0 72 % '.label_names' is similar to .comp_names field holding the names for
wolffd@0 73 % each data label column
wolffd@0 74 %
wolffd@0 75 % REQUIRED INPUT ARGUMENTS
wolffd@0 76 %
wolffd@0 77 % D (matrix) The data matrix, size dlen x dim. The data matrix may
wolffd@0 78 % contain unknown values, indicated by NaNs.
wolffd@0 79 %
wolffd@0 80 % OPTIONAL INPUT ARGUMENTS
wolffd@0 81 %
wolffd@0 82 % argID (string) Argument identifier string (see below).
wolffd@0 83 % value (varies) Value for the argument (see below).
wolffd@0 84 %
wolffd@0 85 % The optional arguments can be given as 'argID',value -pairs as
wolffd@0 86 % listed below. If an argument is given value multiple times, the
wolffd@0 87 % last one is used.
wolffd@0 88 %
wolffd@0 89 % 'labels' (string array / cellstr) labels for each data vector,
wolffd@0 90 % size dlen x m
wolffd@0 91 % 'name' (string) data name
wolffd@0 92 % 'comp_names' (string array / cellstr) component names, size dim x 1
wolffd@0 93 % 'comp_norm' (cell array) normalization operations for each
wolffd@0 94 % component, size dim x 1. Each cell is either empty,
wolffd@0 95 % or a cell array of normalization structs.
wolffd@0 96 % 'label_names'(string array / cellstr) label names, size m x 1
wolffd@0 97 %
wolffd@0 98 % OUTPUT ARGUMENTS
wolffd@0 99 %
wolffd@0 100 % sD (struct) the data struct
wolffd@0 101 %
wolffd@0 102 % EXAMPLES
wolffd@0 103 %
wolffd@0 104 % Simplest case:
wolffd@0 105 % D = rand(8, 3); % 8 3-dimensional vectors
wolffd@0 106 % sD = som_data_struct(D);
wolffd@0 107 %
wolffd@0 108 % With optional arguments, the other fields can be given values:
wolffd@0 109 % labs = cell(8, 1); labs{1, 1} = 'first_label';
wolffd@0 110 % cnames = {'first'; 'second'; 'third'};
wolffd@0 111 %
wolffd@0 112 % sD = som_data_struct(D,'labels',labs,'name','a data struct');
wolffd@0 113 % sD = som_data_struct(D,'comp_names',cnames);
wolffd@0 114 %
wolffd@0 115 % SEE ALSO
wolffd@0 116 %
wolffd@0 117 % som_set Set values and create SOM Toolbox structs.
wolffd@0 118 % som_map_struct Create a map struct.
wolffd@0 119
wolffd@0 120 % Copyright (c) 1997-2000 by the SOM toolbox programming team.
wolffd@0 121 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 122
wolffd@0 123 % Version 1.0beta ecco 071197
wolffd@0 124 % Version 2.0beta juuso 101199
wolffd@0 125
wolffd@0 126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 127
wolffd@0 128 % data
wolffd@0 129 [dlen dim] = size(D);
wolffd@0 130
wolffd@0 131 % default values
wolffd@0 132 if ~isempty(inputname(1)), name = inputname(1);
wolffd@0 133 else name = 'unnamed'; end
wolffd@0 134 labels = cell(dlen,1);
wolffd@0 135 labels(1:dlen) = {''};
wolffd@0 136 %for i=1:dlen, labels{i} = ''; end
wolffd@0 137 comp_names = cell(dim,1);
wolffd@0 138 for i = 1:dim, comp_names{i} = sprintf('Variable%d', i); end
wolffd@0 139 comp_norm = cell(dim,1);
wolffd@0 140 label_names = [];
wolffd@0 141
wolffd@0 142 % varargin
wolffd@0 143 i=1;
wolffd@0 144 while i<=length(varargin),
wolffd@0 145 argok = 1;
wolffd@0 146 if ischar(varargin{i}),
wolffd@0 147 switch varargin{i},
wolffd@0 148 % argument IDs
wolffd@0 149 case 'comp_names', i=i+1; comp_names = varargin{i};
wolffd@0 150 case 'labels', i=i+1; labels = varargin{i};
wolffd@0 151 case 'name', i=i+1; name = varargin{i};
wolffd@0 152 case 'comp_norm', i=i+1; comp_norm = varargin{i};
wolffd@0 153 case 'label_names',i=i+1; label_names = varargin{i};
wolffd@0 154 otherwise argok=0;
wolffd@0 155 end
wolffd@0 156 else
wolffd@0 157 argok = 0;
wolffd@0 158 end
wolffd@0 159 if ~argok,
wolffd@0 160 disp(['(som_data_struct) Ignoring invalid argument #' num2str(i+1)]);
wolffd@0 161 end
wolffd@0 162 i = i+1;
wolffd@0 163 end
wolffd@0 164
wolffd@0 165 % create struct
wolffd@0 166 sData = som_set('som_data','data',D,'labels',labels,...
wolffd@0 167 'name',name,'comp_names',comp_names,...
wolffd@0 168 'comp_norm',comp_norm,'label_names',label_names);
wolffd@0 169
wolffd@0 170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 171
wolffd@0 172
wolffd@0 173