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