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

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