📄 som_set.m
字号:
if ischar(content), content = cellstr(content); elseif ~iscellstr(content), l = prod(size(content)); for j=1:l, if ischar(content{j}), if ~isempty(content{j}), msg = 'Invalid ''labels'' array.'; isok = 0; break; else content{j} = ''; end end end end if isok, sS.labels = content; end end case 'topol', if ~isstruct(content), msg = '''topol'' should be a topology struct.'; elseif ~isfield(content,'msize') | ... ~isfield(content,'lattice') | ... ~isfield(content,'shape'), msg = '''topol'' is not a valid topology struct.'; elseif prod(content.msize) ~= munits, msg = '''topol''.msize does not match the number of map units.'; else sS.topol = content; isok = 1; end case 'msize', if ~isnumeric(content) | ~isvector | ~ispositive | ~isinteger, msg = '''msize'' should be a vector with positive integer elements.'; elseif prod(content) ~= munits, msg = '''msize'' does not match the map size.'; else sS.topol.msize = content; isok = 1; end case 'lattice', if ~ischar(content), msg = '''lattice'' should be a string'; elseif ~strcmp(content,'rect') & ~strcmp(content,'hexa'), msg = ['Unknown lattice type: ' content]; sS.topol.lattice = content; isok = 1; else sS.topol.lattice = content; isok = 1; end case 'shape', if ~ischar(content), msg = '''shape'' should be a string'; elseif ~strcmp(content,'sheet') & ~strcmp(content,'cyl') & ... ~strcmp(content,'toroid'), msg = ['Unknown shape type:' content]; sS.topol.shape = content; isok = 1; else sS.topol.shape = content; isok = 1; end case 'neigh', if ~ischar(content), msg = '''neigh'' should be a string'; elseif ~strcmp(content,'gaussian') & ~strcmp(content,'ep') & ... ~strcmp(content,'cutgauss') & ~strcmp(content,'bubble'), msg = ['Unknown neighborhood function: ' content]; sS.neigh = content; isok = 1; else sS.neigh = content; isok = 1; end case 'mask', if size(content,1) == 1, content = content'; end if ~isnumeric(content) | size(content) ~= [dim 1], msg = '''mask'' should be a column vector (size dim x 1).'; else sS.mask = content; isok = 1; end case 'name', if ~ischar(content), msg = '''name'' should be a string.'; else sS.name = content; isok = 1; end case 'comp_names', if ~iscell(content) & ~ischar(content), msg = '''comp_names'' should be a cell string or a string array.'; elseif length(content) ~= dim, msg = 'Length of ''comp_names'' should be equal to dim.'; else if ischar(content), content = cellstr(content); end if size(content,1)==1, content = content'; end sS.comp_names = content; isok = 1; end case 'comp_norm', if ~iscell(content) & length(content)>0, msg = '''comp_norm'' should be a cell array.'; elseif length(content) ~= dim, msg = 'Length of ''comp_norm'' should be equal to dim.'; else isok = 1; for j=1:length(content), if ~isempty(content{j}) & (~isfield(content{j}(1),'type') | ... ~strcmp(content{j}(1).type,'som_norm')), msg = 'Each cell in ''comp_norm'' should be either empty or type ''som_norm''.'; isok = 0; break; end end if isok, sS.comp_norm = content; end end case 'trainhist', if ~isstruct(content) & ~isempty(content), msg = '''trainhist'' should be a struct array or empty.'; else isok = 1; for j=1:length(content), if ~isfield(content(j),'type') | ~strcmp(content(j).type,'som_train'), msg = 'Each cell in ''trainhist'' should be of type ''som_train''.'; isok = 0; break; end end if isok, sS.trainhist = content; end end otherwise, msg = ['Invalid field for map struct: ' field]; end case 'som_data', [dlen dim] = size(sS.data); switch field, case 'data', [dummy dim2] = size(content); if prod(si)==0, msg = '''data'' is empty'; elseif ~isnumeric(content), msg = '''data'' should be numeric matrix.'; elseif dim ~= dim2 & ~isempty(sS.data), msg = 'New ''data'' must have the same dimension as old one.'; else sS.data = content; isok = 1; end case 'labels', if isempty(content), sS.labels = cell(dlen,1); isok = 1; elseif size(content,1) ~= dlen, msg = 'Length of ''labels'' must be equal to the number of data vectors.'; elseif ~iscell(content) & ~ischar(content), msg = '''labels'' must be a string array or a cell array/matrix.'; else isok = 1; if ischar(content), content = cellstr(content); elseif ~iscellstr(content), l = prod(size(content)); for j=1:l, if ~ischar(content{j}), if ~isempty(content{j}), msg = 'Invalid ''labels'' array.'; isok = 0; j break; else content{j} = ''; end end end end if isok, sS.labels = content; end end case 'name', if ~ischar(content), msg = '''name'' should be a string.'; else sS.name = content; isok = 1; end case 'comp_names', if ~iscell(content) & ~ischar(content), msg = '''comp_names'' should be a cell string or a string array.'; elseif length(content) ~= dim, msg = 'Length of ''comp_names'' should be equal to dim.'; else if ischar(content), content = cellstr(content); end if size(content,1)==1, content = content'; end sS.comp_names = content; isok = 1; end case 'comp_norm', if ~iscell(content) & length(content)>0, msg = '''comp_norm'' should be a cell array.'; elseif length(content) ~= dim, msg = 'Length of ''comp_norm'' should be equal to dim.'; else isok = 1; for j=1:length(content), if ~isempty(content{j}) & (~isfield(content{j}(1),'type') | ... ~strcmp(content{j}(1).type,'som_norm')), msg = 'Each cell in ''comp_norm'' should be either empty or type ''som_norm''.'; isok = 0; break; end end if isok, sS.comp_norm = content; end end case 'label_names', if ~iscell(content) & ~ischar(content) & ~isempty(content), msg = ['''label_names'' should be a cell string, a string array or' ... ' empty.']; else if ~isempty(content), if ischar(content), content = cellstr(content); end if size(content,1)==1, content = content'; end end sS.label_names = content; isok = 1; end otherwise, msg = ['Invalid field for data struct: ' field]; end case 'som_topol', switch field, case 'msize', if ~isnumeric(content) | ~isvector | ~ispositive | ~isinteger, msg = '''msize'' should be a vector with positive integer elements.'; else sS.msize = content; isok=1; end case 'lattice', if ~ischar(content), msg = '''lattice'' should be a string'; elseif ~strcmp(content,'rect') & ~strcmp(content,'hexa'), msg = ['Unknown lattice type: ' content]; sS.lattice = content; isok = 1; else sS.lattice = content; isok = 1; end case 'shape', if ~ischar(content), msg = '''shape'' should be a string'; elseif ~strcmp(content,'sheet') & ~strcmp(content,'cyl') & ... ~strcmp(content,'toroid'), msg = ['Unknown shape type: ' content]; sS.shape = content; isok = 1; else sS.shape = content; isok = 1; end otherwise, msg = ['Invalid field for topology struct: ' field]; end case 'som_train', switch field, case 'algorithm', if ~ischar(content), msg = '''algorithm'' should be a string.'; else sS.algorithm = content; isok = 1; end case 'data_name', if ~ischar(content), msg = '''data_name'' should be a string'; else sS.data_name = content; isok = 1; end case 'neigh', if ~ischar(content), msg = '''neigh'' should be a string'; elseif ~isempty(content) & ~strcmp(content,'gaussian') & ~strcmp(content,'ep') & ... ~strcmp(content,'cutgauss') & ~strcmp(content,'bubble'), msg = ['Unknown neighborhood function: ' content]; sS.neigh = content; isok = 1; else sS.neigh = content; isok = 1; end case 'mask', if size(content,1) == 1, content = content'; end dim = size(content,1); %[munits dim] = size(sS.data); if ~isnumeric(content) | size(content) ~= [dim 1], msg = '''mask'' should be a column vector (size dim x 1).'; else sS.mask = content; isok = 1; end case 'radius_ini', if ~isnumeric(content) | ~isscalar, msg = '''radius_ini'' should be a scalar.'; else sS.radius_ini = content; isok = 1; end case 'radius_fin', if ~isnumeric(content) | ~isscalar, msg = '''radius_fin'' should be a scalar.'; else sS.radius_fin = content; isok = 1; end case 'alpha_ini', if ~isnumeric(content) | ~isscalar, msg = '''alpha_ini'' should be a scalar.'; else sS.alpha_ini = content; isok = 1; end case 'alpha_type', if ~ischar(content), msg = '''alpha_type'' should be a string'; elseif ~strcmp(content,'linear') & ~strcmp(content,'inv') & ... ~strcmp(content,'power') & ~strcmp(content,'constant') & ~strcmp(content,''), msg = ['Unknown alpha type: ' content]; sS.alpha_type = content; isok = 1; else sS.alpha_type = content; isok = 1; end case 'trainlen', if ~isnumeric(content) | ~isscalar, msg = '''trainlen'' should be a scalar.'; else sS.trainlen = content; isok = 1; end case 'time', if ~ischar(content), msg = '''time'' should be a string'; else sS.time = content; isok = 1; end otherwise, msg = ['Invalid field for train struct: ' field]; end case 'som_norm', switch field, case 'method', if ~ischar(field), msg = '''method'' should be a string.'; else sS.method = content; isok = 1; end case 'params', sS.params = content; isok = 1; case 'status', if ~ischar(content), msg = '''status'' should be a string'; elseif ~strcmp(content,'done') & ~strcmp(content,'undone') & ... ~strcmp(content,'uninit'), msg = ['Unknown status type: ' content]; sS.status = content; isok = 1; else sS.status = content; isok = 1; end otherwise, msg = ['Invalid field for normalization struct: ' field]; end case 'som_grid', if any(strcmp(field,{'lattice', 'shape', 'msize', 'coord',... 'line', 'linecolor', 'linewidth', ... 'marker', 'markersize', 'markercolor', 'surf', ... 'label', 'labelcolor', 'labelsize'})), warning('No checking done on field identifier or content.'); sS = setfield(sS,field,content); isok = 1; else msg = ['Invalid field for grid struct: ' field]; end otherwise, error('Unrecognized structure.'); end msgs{i} = msg; ok(i) = isok; end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% returnif nargout < 2, for i=1:p, if ~isempty(msgs{i}), if ~ok(i), fprintf(1,'[Error! '); else fprintf(1,'[Notice '); end fprintf(1,'in setting %s] ',varargin{2*i-1}); fprintf(1,'%s\n',msgs{i}); end endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -