wolffd@0: function flag=vis_valuetype(value, valid, str); wolffd@0: wolffd@0: % VIS_VALUETYPE Used for type checks in SOM Toolbox visualization routines wolffd@0: % wolffd@0: % flag = vis_valuetype(value, valid, str) wolffd@0: % wolffd@0: % Input and output arguments: wolffd@0: % value (varies) variable to be checked wolffd@0: % valid (cell array) size 1xN, cells are strings or vectors (see below) wolffd@0: % str (string) 'all' or 'any' (default), determines whether wolffd@0: % all or just any of the types listed in argument 'valid' wolffd@0: % should be true for 'value' wolffd@0: % wolffd@0: % flag (scalar) 1 or 0 (true or false) wolffd@0: % wolffd@0: % This is an internal function of SOM Toolbox visualization. It makes wolffd@0: % various type checks. For example: wolffd@0: % wolffd@0: % % Return 1 if X is a numeric scalar otherwise 0: wolffd@0: % f=vis_valuetype(X,{'1x1'}); wolffd@0: % wolffd@0: % % Return 1 if X is a ColorSpec, that is, a 1x3 vector presenting an RGB wolffd@0: % % value or any of strings 'red','blue','green','yellow','magenta','cyan', wolffd@0: % % 'white' or 'black' or their shortenings 'r','g','b','y','m','c','w','k': wolffd@0: % f=vis_valueype(X,{'1x3rgb','colorstyle'}) wolffd@0: % wolffd@0: % % Return 1 if X is _both_ 10x3 size numeric matrix and has RGB values as rows wolffd@0: % f=vis_valuetype(X,{'nx3rgb',[10 3]},'all') wolffd@0: % wolffd@0: % Strings that may be used in argument valid: wolffd@0: % id is true if value is wolffd@0: % wolffd@0: % [n1 n2 ... nn] any n1 x n2 x ... x nn sized numeric matrix wolffd@0: % '1x1' scalar (numeric) wolffd@0: % '1x2' 1x2 vector (numeric) wolffd@0: % 'nx1' any nx1 numeric vector wolffd@0: % 'nx2' nx2 wolffd@0: % 'nx3' nx3 wolffd@0: % 'nxn' any numeric square matrix wolffd@0: % 'nxn[0,1]' numeric square matrix with values in interval [0,1] wolffd@0: % 'nxm' any numeric matrix wolffd@0: % '1xn' any 1xn numeric vector wolffd@0: % '1x3rgb' 1x3 vector v for which all(v>=0 & v<=1), e.g., a RGB code wolffd@0: % 'nx3rgb' nx3 numeric matrix that contains n RGB values as rows wolffd@0: % 'nx3dimrgb' nx3xdim numeric matrix that contains RGB values wolffd@0: % 'nxnx3rgb' nxnx3 numeric matrix of nxn RGB triples wolffd@0: % 'none' string 'none' wolffd@0: % 'xor' string 'xor' wolffd@0: % 'indexed' string 'indexed' wolffd@0: % 'colorstyle' strings 'red','blue','green','yellow','magenta','cyan','white' wolffd@0: % or 'black', or 'r','g','b','y','m','c','w','k' wolffd@0: % 'markerstyle' any of Matlab's marker chars '.','o','x','+','*','s','d','v', wolffd@0: % '^','<','>','p'or 'h' wolffd@0: % 'linestyle' any or Matlab's line style strings '-',':','--', or '-.' wolffd@0: % 'cellcolumn' a nx1 cell array wolffd@0: % 'topol_cell' {lattice, msize, shape} wolffd@0: % 'topol_cell_no_shape' {lattice, msize} wolffd@0: % 'string' any string (1xn array of char) wolffd@0: % 'chararray' any MxN char array wolffd@0: wolffd@0: % Copyright (c) 1999-2000 by the SOM toolbox programming team. wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta Johan 201099 juuso 280800 wolffd@0: wolffd@0: if nargin == 2 wolffd@0: str='any'; wolffd@0: end wolffd@0: wolffd@0: flag=0; wolffd@0: sz=size(value); wolffd@0: dims=ndims(value); wolffd@0: wolffd@0: % isnumeric wolffd@0: numeric=isnumeric(value); wolffd@0: character=ischar(value); wolffd@0: wolffd@0: % main loop: go through all types in arg. 'valid' wolffd@0: for i=1:length(valid), wolffd@0: if isnumeric(valid{i}), % numeric size for double matrix wolffd@0: if numeric & length(valid{i}) == dims, wolffd@0: flag(i)=all(sz == valid{i}); wolffd@0: else wolffd@0: flag(i)=0; % not numeric or wrong dimension wolffd@0: end wolffd@0: else wolffd@0: msg=''; % for a error message inside try wolffd@0: try wolffd@0: switch valid{i} wolffd@0: wolffd@0: % scalar wolffd@0: case '1x1' wolffd@0: flag(i)=numeric & dims == 2 & sz(1)==1 & sz(2) ==1; wolffd@0: wolffd@0: % 1x2 numeric vector wolffd@0: case '1x2' wolffd@0: flag(i)=numeric & dims == 2 & sz(1)==1 & sz(2) == 2; wolffd@0: wolffd@0: % 1xn numeric vector wolffd@0: case '1xn' wolffd@0: flag(i)=numeric & dims == 2 & sz(1) == 1; wolffd@0: wolffd@0: % any numeric matrix wolffd@0: case 'nxm' wolffd@0: flag(i)=numeric & dims == 2; wolffd@0: wolffd@0: % nx3 numeric matrix wolffd@0: case 'nx3' wolffd@0: flag(i)=numeric & dims == 2 & sz(2) == 3; wolffd@0: wolffd@0: % nx2 numeric matrix wolffd@0: case 'nx2' wolffd@0: flag(i)=numeric & dims == 2 & sz(2) == 2; wolffd@0: wolffd@0: % nx1 numeric vector wolffd@0: case 'nx1' wolffd@0: flag(i)=numeric & dims == 2 & sz(2) == 1; wolffd@0: wolffd@0: % nx1xm numric matrix wolffd@0: case 'nx1xm' wolffd@0: flag(i)=numeric & dims == 3 & sz(2) == 1; wolffd@0: wolffd@0: % nx3 matrix of RGB triples wolffd@0: case 'nx3rgb' wolffd@0: flag(i)=numeric & dims == 2 & sz(2) == 3 & in0_1(value); wolffd@0: wolffd@0: % RGB triple (ColorSpec vector) wolffd@0: case '1x3rgb' wolffd@0: flag(i) = numeric & dims == 2 & sz(1)==1 & sz(2) == 3 & in0_1(value); wolffd@0: wolffd@0: % any square matrix wolffd@0: case 'nxn' wolffd@0: flag(i)=numeric & dims == 2 & sz(1) == sz(2); wolffd@0: wolffd@0: % nx3xdim array of nxdim RGB triples wolffd@0: case 'nx3xdimrgb' wolffd@0: flag(i)=numeric & dims == 3 & sz(2) == 3 & in0_1(value); wolffd@0: wolffd@0: % nxnx3 array of nxn RGB triples wolffd@0: case 'nxnx3rgb' wolffd@0: flag(i)= numeric & dims == 3 & sz(1) == sz(2) & sz(3) == 3 ... wolffd@0: & in0_1(value); wolffd@0: wolffd@0: % nxn matrix of values between [0,1] wolffd@0: case 'nxn[0,1]' wolffd@0: wolffd@0: flag(i)=numeric & dims == 2 & sz(1) == sz(2) & in0_1(value); wolffd@0: wolffd@0: % string 'indexed' wolffd@0: case 'indexed' wolffd@0: flag(i) = ischar(value) & strcmp(value,'indexed'); wolffd@0: wolffd@0: % string 'none' wolffd@0: case 'none' wolffd@0: flag(i) = character & strcmp(value,'none'); wolffd@0: wolffd@0: % string 'xor' wolffd@0: case 'xor' wolffd@0: flag(i) = character & strcmp(value,'xor'); wolffd@0: wolffd@0: % any string (1xn char array) wolffd@0: case 'string' wolffd@0: flag(i) = character & dims == 2 & sz(1)<=1; wolffd@0: wolffd@0: % any char array wolffd@0: case 'chararray' wolffd@0: flag(i) = character & dims == 2 & sz(1)>0; wolffd@0: wolffd@0: % ColorSpec string wolffd@0: case 'colorstyle' wolffd@0: flag(i)=(character & sz(1) == 1 & sz(2) == 1 & ... wolffd@0: any(ismember('ymcrgbwk',value))) | ... wolffd@0: (ischar(value) & any(strcmp(value,{'none','yellow','magenta',... wolffd@0: 'cyan','red','green','blue','white','black'}))); wolffd@0: wolffd@0: % any valid Matlab's Marker wolffd@0: case 'markerstyle' wolffd@0: flag(i)=character & sz(1) == 1 & sz(2) == 1 & ... wolffd@0: any(ismember('.ox+*sdv^<>ph',value)); wolffd@0: wolffd@0: % any valid Matlab's LineStyle wolffd@0: case 'linestyle' wolffd@0: str=strrep(strrep(strrep(value,'z','1'),'--','z'),'-.','z'); wolffd@0: flag(i)=character & any(ismember(str,'z-:')) & sz(1)==1 & (sz(2)==1 | sz(2)==2); wolffd@0: wolffd@0: % any struct wolffd@0: case 'struct' wolffd@0: flag(i)=isstruct(value); wolffd@0: wolffd@0: % nx1 cell array of strings wolffd@0: case 'cellcolumn_of_char' wolffd@0: flag(i)=iscell(value) & dims == 2 & sz(2)==1; wolffd@0: try, char(value); catch, flag(i)=0; end wolffd@0: wolffd@0: % mxn cell array of strings wolffd@0: case '2Dcellarray_of_char' wolffd@0: flag(i)=iscell(value) & dims == 2; wolffd@0: try, char(cat(2,value{:})); catch, flag(i)=0; end wolffd@0: wolffd@0: % valid {lattice, msize} wolffd@0: case 'topol_cell_no_shape' wolffd@0: flag(i)=1; wolffd@0: if ~iscell(value) | length(size(value)) ~= 2 | size(value,2)~=2 wolffd@0: flag(i)=0; wolffd@0: else wolffd@0: if vis_valuetype(value{1},{'string'}), wolffd@0: switch value{1} wolffd@0: case { 'hexa','rect'} wolffd@0: ; wolffd@0: otherwise wolffd@0: flag(i)=0; wolffd@0: end wolffd@0: end wolffd@0: if ~vis_valuetype(value{2},{'1xn'}), wolffd@0: flag(i)=0; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % valid {lattice, msize, shape} wolffd@0: case 'topol_cell' wolffd@0: flag(i)=1; wolffd@0: if ~iscell(value) | length(size(value)) ~= 2 | size(value,2) ~= 3, wolffd@0: flag(i)=0; wolffd@0: else wolffd@0: if vis_valuetype(value{1},{'string'}), wolffd@0: switch value{1} wolffd@0: case { 'hexa','rect'} wolffd@0: ; wolffd@0: otherwise wolffd@0: flag(i)=0; wolffd@0: end wolffd@0: end wolffd@0: if ~vis_valuetype(value{2},{'1xn'}) wolffd@0: flag(i)=0; wolffd@0: end wolffd@0: if ~vis_valuetype(value{3},{'string'}) wolffd@0: flag(i)=0; wolffd@0: else wolffd@0: switch value{3} wolffd@0: case { 'sheet','cyl', 'toroid'} wolffd@0: ; wolffd@0: otherwise wolffd@0: flag(i)=0; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: otherwise wolffd@0: msg='Unknown valuetype!'; wolffd@0: end wolffd@0: catch wolffd@0: % error during type check is due to wrong type of value: wolffd@0: % lets set flag(i) to 0 wolffd@0: flag(i)=0; wolffd@0: end wolffd@0: % Unknown indetifier? wolffd@0: error(msg); wolffd@0: end wolffd@0: % set flag according to 3rd parameter (all ~ AND, any ~ OR) wolffd@0: if strcmp(str,'all'); wolffd@0: flag=all(flag); wolffd@0: else wolffd@0: flag=any(flag); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function f=in0_1(value) wolffd@0: wolffd@0: f=all(value(:) >= 0 & value(:)<=1);