wolffd@0: function h=som_show_add(mode,D,varargin) wolffd@0: wolffd@0: %SOM_SHOW_ADD Shows hits, labels and trajectories on SOM_SHOW visualization wolffd@0: % wolffd@0: % h = som_show_add(mode, D, ['argID',value,...]) wolffd@0: % wolffd@0: % som_show_add('label',sMap) wolffd@0: % som_show_add('hit',som_hits(sMap,sD)) wolffd@0: % som_show_add('traj',som_bmus(sMap,sD)) wolffd@0: % som_show_add('comet',som_bmus(sMap,sD)) wolffd@0: % som_show_add('comet',inds, 'markersize', [1 0.2]) wolffd@0: % wolffd@0: % Input and output arguments ([]'s are optional): wolffd@0: % mode (string) operation mode 'label', 'hit', 'traj', 'comet' wolffd@0: % D (varies) depending on operation mode wolffd@0: % In 'label' mode gives the labels wolffd@0: % (struct) map struct, the .labels field of which is used wolffd@0: % (cell array of strings) size munits x number_of_labels wolffd@0: % In 'hit' mode gives the hit histogram(s) wolffd@0: % (matrix) size munits x k, if k>1, D gives hit histograms wolffd@0: % for k different sets of data (e.g. k classes). wolffd@0: % In 'traj' and 'comet' modes gives the trace of the trajectory wolffd@0: % (vector) size N x 1, D(1) is the current and D(end) wolffd@0: % is oldest item of the trajectory wolffd@0: % [argID, (string) Additional arguments are given as argID, value wolffd@0: % value] (varies) pairs. Depend on the operation mode (see below). wolffd@0: % wolffd@0: % h (vector) handles to the created objects wolffd@0: % wolffd@0: % Here are the valid argument IDs and corresponding values. Most of wolffd@0: % them depend on the operation mode: wolffd@0: % wolffd@0: % all modes wolffd@0: % 'SubPlot' (vector) which subplots are affected (default: current) wolffd@0: % (string) 'all': all subplots are affected wolffd@0: % mode = 'label' wolffd@0: % 'TextSize' (scalar) text size in points wolffd@0: % 'TextColor' (string) ColorSpec, 'xor' or 'none': label color wolffd@0: % wolffd@0: % mode = 'hit' wolffd@0: % 'EdgeColor' (string) ColorSpec, 'none' wolffd@0: % 'MarkerSize' (scalar) maximum marker size wolffd@0: % if k == 1, wolffd@0: % 'Marker' (string) 'lattice', Matlab's built-in markerstyles, 'none' wolffd@0: % 'MarkerColor'(string) Colorspec, 'none': fill color for markers wolffd@0: % 'Text' (string) 'on', 'off': whether to write the number of hits wolffd@0: % 'TextColor' (string) ColorSpec, 'xor': text color if Text is 'on' wolffd@0: % 'TextSize' (scalar) text font size in points if Text is 'on' wolffd@0: % if k > 1, wolffd@0: % 'SizeFactor' (string) 'common', 'separate': size scaling wolffd@0: % 'Marker' (string) 'lattice', Matlab's built-in markerstyles, 'pie', 'none' wolffd@0: % (cell array) size k x 1, marker style for each histogram wolffd@0: % 'MarkerColor'(string) Colorspec, 'none': fill color for markers wolffd@0: % (matrix) size k x 3, color for each histogram wolffd@0: % wolffd@0: % mode = 'traj' wolffd@0: % 'TrajWidth' (scalar) basic trajectory line width in points wolffd@0: % 'WidthFactor'(string) 'hit' or 'equal': effect of hits on line width wolffd@0: % 'TrajColor' (string) ColorSpec, 'xor': color for trajectory line wolffd@0: % 'Marker' (string) 'lattice', Matlab's built-in markerstyles, 'none' wolffd@0: % 'MarkerSize' (scalar) basic marker size (in points) wolffd@0: % 'SizeFactor' (string) 'equal', 'hit' (equal size/size depends on freq.) wolffd@0: % 'MarkerColor'(string) Colorspec, 'none': color of markers wolffd@0: % 'EdgeColor' (string) ColorSpec, 'none': edgecolor of markers wolffd@0: % wolffd@0: % mode = 'comet' wolffd@0: % 'Marker' (string) 'lattice', Matlab's built-in markerstyles wolffd@0: % 'MarkerColor'(string) ColorSpec, 'none': color for the markers wolffd@0: % (matrix) size N x 3, RGB color for each step wolffd@0: % 'EdgeColor' (string) ColorSpec, 'none': edgecolor for markers wolffd@0: % 'MarkerSize' (vector) size 1 x 2, size of comet core and tail wolffd@0: % wolffd@0: % For more help, try 'type som_show_add' or check out online documentation. wolffd@0: % See also SOM_SHOW. wolffd@0: wolffd@0: %%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % wolffd@0: % som_show_add wolffd@0: % wolffd@0: % PURPOSE wolffd@0: % wolffd@0: % Shows hits, labels and trajectories on SOM_SHOW visualization wolffd@0: % wolffd@0: % SYNTAX wolffd@0: % wolffd@0: % h = som_show_add(mode, D); wolffd@0: % h = som_show_add(..., 'argID', value); wolffd@0: % wolffd@0: % DESCRIPTION wolffd@0: % wolffd@0: % The SOM_SHOW function makes the basic visualization of the SOM. wolffd@0: % With SOM_SHOW_ADD one can set labels, hit histogarms or different wolffd@0: % trajectories on this visualization. wolffd@0: % wolffd@0: % labels (mode = 'label') wolffd@0: % wolffd@0: % Labels are strings describing the units. They may be, e.g., a result wolffd@0: % of SOM_AUTOLABEL function. Labels are centered on the unit so that wolffd@0: % multiple labels are in a column. wolffd@0: % wolffd@0: % hit histograms (mode = 'hit') wolffd@0: % wolffd@0: % Hit histograms indicate how the best matching units of a data wolffd@0: % set/some data sets are distribited on a SOM. The hit histogram can wolffd@0: % be calculated using function SOM_HITS. wolffd@0: % wolffd@0: % trajectories (mode = 'traj' or mode = 'comet') wolffd@0: % wolffd@0: % Trajectories show the best matching units for a data set that is wolffd@0: % time (or any ordered) series. It may be either a line connecting the wolffd@0: % consecutive best matching units ('traj' mode) or a "comet" wolffd@0: % trajectory where the current (first sample in D) best matching unit wolffd@0: % has biggest marker and the oldest (last sample) has smallest wolffd@0: % marker ('comet' mode). wolffd@0: % wolffd@0: % NOTE: that the SOM_SHOW_ADD function can only be applied to wolffd@0: % figures that have been drawn by SOM_SHOW. wolffd@0: % wolffd@0: % KNOWN BUGS wolffd@0: % wolffd@0: % for 'hit' mode, if the given hit matrix is all zeros, a series of wolffd@0: % error messages is generated wolffd@0: % wolffd@0: % REQUIRED INPUT ARGUMENTS wolffd@0: % wolffd@0: % mode (string) Visuzalization mode wolffd@0: % 'label' map labeling wolffd@0: % 'hit' hit histograms wolffd@0: % 'traj' line style trajectory wolffd@0: % 'comet' comet style trajectory wolffd@0: % wolffd@0: % D (vector, map struct, cell array of strings) Data wolffd@0: % wolffd@0: % The valid value of D depends on the visualization mode: wolffd@0: % wolffd@0: % Mode Valid D wolffd@0: % 'label' map struct or Mxl cell array of strings, where wolffd@0: % M is number of map units and l maximum numer of wolffd@0: % labels in unit. wolffd@0: % wolffd@0: % 'hit' Mx1 vector or MxK matrix, where M is number of map wolffd@0: % units and K is number of hit histograms (of K wolffd@0: % different classes of data) to be shown wolffd@0: % wolffd@0: % 'comet' Lx1 vector of best matchig unit indices that have to wolffd@0: % 'traj' be in range of the map that is in the figure. L is wolffd@0: % the length of trajectory wolffd@0: % wolffd@0: % OPTIONAL INPUT ARGUMENTS wolffd@0: % wolffd@0: % Optional arguments must be given as 'argument identifier', value wolffd@0: % -pairs. This section is divided in four parts because each mode wolffd@0: % functions in a different way, though they may have same identifier wolffd@0: % names. wolffd@0: % wolffd@0: % If user specifies an identifier that is not operational in the wolffd@0: % specified mode, the functions gives a warning message. If the wolffd@0: % identifier does not exist in any mode the execution is terminated wolffd@0: % and an error message is returned. wolffd@0: % wolffd@0: % GENERAL OPTIONAL INPUT ARGUMENTS (in all modes) wolffd@0: % wolffd@0: % 'SubPlot' Target subplots in the figure wolffd@0: % (vector) Subplots' ordinal numbers in a vector. By default wolffd@0: % the target is the current subplot (see GCA). wolffd@0: % (string) String 'all' means all subplots. wolffd@0: % wolffd@0: % 'Marker' Data marker (not in use in 'label' mode) wolffd@0: % (string) 'none': sets the markers off wolffd@0: % 'lattice': sets the marker shape according to the wolffd@0: % lattice of the underlying map, i.e. it gives wolffd@0: % rectangles if underlying map lattice is 'rect' and wolffd@0: % hexagons for 'hexa', respectively wolffd@0: % any of the Matlab's built-in marker styles: 'o', 's', wolffd@0: % 'd', 'v', '^', '<' ,'> ', 'p', 'h', 'x', '.', '*', '+' wolffd@0: % wolffd@0: % NOTE that '.','x','+' or '*' are not recommended since wolffd@0: % they have only edgecolor and many visualizations are wolffd@0: % based on _face_ color. wolffd@0: % wolffd@0: % NOTE there is an important difference between built-in wolffd@0: % markers. If figure size is changed the 'lattice' wolffd@0: % markers are rescaled but the built-in markers stay at wolffd@0: % fixed size, and consequently, the size unit for wolffd@0: % 'lattice' markers is normalized but for built-in wolffd@0: % markers the size is given in points. For 'lattice' wolffd@0: % markers size 1 means the size of the map unit. wolffd@0: % wolffd@0: % NOTE that in 'hit' mode there are some additional features. wolffd@0: % wolffd@0: % 'EdgeColor' Sets edgecolor for the markers (not in use in 'label' mode) wolffd@0: % (string) ColorSpec, e.g. 'r', gives each edge the specified color wolffd@0: % 'none': sets markers edges invisible wolffd@0: % Default is 'none' - except if MarkerColor is set to 'none' the wolffd@0: % defaults is 'black'. wolffd@0: % wolffd@0: % OPTIONAL INPUT ARGUMENTS mode 'label' wolffd@0: % wolffd@0: % Labels are centered on the unit so that multiple labels are in wolffd@0: % a single column. wolffd@0: % wolffd@0: % 'SubPlot' see General Optional Input Arguments wolffd@0: % wolffd@0: % 'TextSize' Text size for labels wolffd@0: % (scalar) Text size in points. Default is 10. wolffd@0: % wolffd@0: % 'TextColor' Text color wolffd@0: % (string) ColorSpec specifies the text color for all labels wolffd@0: % 'xor': gives Matlab's "xor" text color mode where the wolffd@0: % label color depends on background color wolffd@0: % 'none': sets labels invisble (but creates the objects) wolffd@0: % wolffd@0: % OPTIONAL INPUT ARGUMENTS mode 'hit' wolffd@0: % wolffd@0: % The function in mode 'hit' depends on the input argument size. If wolffd@0: % only one hit histogram is drawn (K==1), it is possible to show the wolffd@0: % hits using numbers. This is not possible for multiple hit wolffd@0: % histograms (K>1). wolffd@0: % wolffd@0: % 'SubPlot' see General Optional Input Arguments wolffd@0: % wolffd@0: % 'Marker' Marker style(s) wolffd@0: % (string) As in General Optional Input Arguments. In addition wolffd@0: % 'pie': sets pie charts for markers. The size of the wolffd@0: % pie in each unit describes the number of total hits in the wolffd@0: % unit and the share of each sector is the relative amount of wolffd@0: % hits in each class (requires multiple histograms). Color for wolffd@0: % each class is set by MarkerColor. Default coloring wolffd@0: % is hsv(K), where K is the number of hit histograms (classes). wolffd@0: % (cell array) size K x 1, of built-in marker style characters. K is wolffd@0: % number of histograms (classes), i.e., same as size(D,2) wolffd@0: % where D is the second input argument. Cell value is wolffd@0: % valid only if multiple histograms are specified (K>1). wolffd@0: % wolffd@0: % NOTE if multiple histograms (classes) are specified wolffd@0: % and Marker is one of the built-in marker styles or wolffd@0: % 'lattice', the markers are drawn in size order from wolffd@0: % largest to smallest. This insures that all markers are wolffd@0: % visible (or at least their edges are). But if two wolffd@0: % markers for different classes in the same node were of wolffd@0: % same size, the other would be totally hidden. In order wolffd@0: % to prevent this, the markers for different classes are wolffd@0: % shifted different amounts from the exact centre of the wolffd@0: % unit. (Evidently, if Marker is 'pie' this problem does wolffd@0: % not exist.) wolffd@0: % wolffd@0: % Default marker is 'lattice' for one histogram and wolffd@0: % 'pie' for multiple histograms. wolffd@0: % wolffd@0: % 'MarkerColor' Marker color(s) wolffd@0: % (string) ColorSpec gives all markers the same color wolffd@0: % 'none': leaves the markes transparent (only edges are visible) wolffd@0: % (matrix) size K x 3, RGB triples for each histogram class wolffd@0: % giving each hit histogram an own color wolffd@0: % wolffd@0: % NOTE that markers '*','+','x', or '.' cannot use wolffd@0: % MarkerColor since these objects have no face (fill) wolffd@0: % color. For them only EdgeColor matters. wolffd@0: % wolffd@0: % 'MarkerSize' Maximum size for marker wolffd@0: % (scalar) set the _maximum_ marker size that corresponds to wolffd@0: % maximum hit count. If Marker is 'pie' or 'lattice' the wolffd@0: % MarkerSize is in normalized scale: 1 correspons to unit size. wolffd@0: % If Marker is one of the built-in styles, MarkerSize is given wolffd@0: % in points. wolffd@0: % wolffd@0: % Marker Default MarkerSize wolffd@0: % 'lattice' 1 (normalized units) wolffd@0: % 'pie' 1 (normalized units) wolffd@0: % 'o','s', etc. 6 (points) wolffd@0: % wolffd@0: % 'SizeFactor' Defines the scaling of the marker sizes in multiple wolffd@0: % histogram case (when Marker is one of the built-in marker wolffd@0: % styles or 'lattice'). wolffd@0: % (string) 'separate' (the default) means that marker size shows wolffd@0: % the share of the data which hits the unit compared to wolffd@0: % amount of data in that class. That is, the size of wolffd@0: % markers show the relative distribution of data on the map wolffd@0: % in each class separately. The maximum size is SizeFactor. wolffd@0: % 'common' means that marker size shows the distribution of wolffd@0: % the data in the different classes compared to wolffd@0: % _the total amount of data_. wolffd@0: % wolffd@0: % 'EdgeColor' Sets edgecolor for the markers, see General wolffd@0: % Optional Input Arguments. Default is 'none' - wolffd@0: % except if MarkerColor is 'none' or Marker is wolffd@0: % 'x','*,'x', or '.'. In these cases default EdgeColor is 'black'. wolffd@0: % wolffd@0: % 'Text' Write/don't write the number of hits on the wolffd@0: % units. This option is not in use for multiple histograms. wolffd@0: % (string) 'on' or 'off' (the default) wolffd@0: % wolffd@0: % 'TextColor' Text color wolffd@0: % (string) ColorSpec gives each letter the same color wolffd@0: % 'xor' gives a "xor" coloring for the text wolffd@0: % wolffd@0: % 'TextSize' Text size (in points) wolffd@0: % (scalar) text size in points, default is 10 wolffd@0: % wolffd@0: % OPTIONAL INPUT ARGUMENTS mode 'traj' wolffd@0: % wolffd@0: % Input D is a Nx1 vector of N BMU indices that describe the trace of the wolffd@0: % comet. First element D(1) is "newest" and D(end) "oldest". Note wolffd@0: % that at least two indeces are expected: size of D must be at wolffd@0: % least 2x1. wolffd@0: % wolffd@0: % 'SubPlot' see General Optional Input Arguments wolffd@0: % wolffd@0: % 'TrajColor' Color for trajectory line wolffd@0: % (string) ColorSpec gives each marker the same color, 'w' by default wolffd@0: % 'none' sets the marker fill invisible: only edges are shown wolffd@0: % wolffd@0: % 'TrajWidth' Maximum width of trajectory line wolffd@0: % (scalar) width in points. Default is 3. wolffd@0: % wolffd@0: % 'WidthFactor' Shows how often edge between two units has been traversed. wolffd@0: % (string) 'hit': the size of the marker shows how frequent the wolffd@0: % trajectory visits the unit (TrajWidth sets the wolffd@0: % maximum size). This is the default. wolffd@0: % 'equal': all lines have the same width (=TrajWidth) wolffd@0: % wolffd@0: % 'Marker' Marker style, see General Optional Input wolffd@0: % Arguments. Default is 'o'. wolffd@0: % wolffd@0: % NOTE Marker style 'lattice' is not valid in mode 'traj'. wolffd@0: % NOTE Markers can be turned off by setting MarkerSize to zero. wolffd@0: % wolffd@0: % 'MarkerSize' Maximum size of markers wolffd@0: % (scalar) Default is 12 (points). wolffd@0: % wolffd@0: % 'SizeFactor' Sets the frequency based marker size or constant marker size. wolffd@0: % (string) 'hit': the size of the marker shows how frequent the wolffd@0: % trajectory visits the unit (MarkerSize sets the wolffd@0: % maximum size). This is the default. wolffd@0: % 'equal': all markers have th esame size (=MarkerSize) wolffd@0: % wolffd@0: % 'MarkerColor' The fill color(s) for hit markers wolffd@0: % (string) ColorSpec gives each marker the same color, default is 'w' wolffd@0: % 'none' sets the marker fill invisible: only edges are shown wolffd@0: % wolffd@0: % NOTE markers '*','+','x', or '.' can't use MarkerColor since wolffd@0: % these objects have no face (fill) color: only EdgeColor wolffd@0: % matters for these markers. wolffd@0: % wolffd@0: % 'EdgeColor' see General Optional Input Arguments. Default is wolffd@0: % 'none' - except if MarkerColor is 'none' or Marker wolffd@0: % is 'x','*','x', or '.'. In these cases default wolffd@0: % EdgeColor is 'white'. wolffd@0: % wolffd@0: % OPTIONAL INPUT ARGUMENTS mode 'comet' wolffd@0: % wolffd@0: % Input D is a Nx1 vector of N BMU indices that describe the trace of wolffd@0: % the comet. First element D(1) is "newest" and D(end) "oldest". Note wolffd@0: % that at least two indeces are expected: size of D must be at least wolffd@0: % 2x1. wolffd@0: % wolffd@0: % 'SubPlot' see General Optional Input Arguments wolffd@0: % wolffd@0: % 'Marker' Marker style, see General Optional Input wolffd@0: % Arguments. Default is 'lattice'. wolffd@0: % wolffd@0: % 'MarkerColor' The fill color(s) for comet markers wolffd@0: % (string) ColorSpec gives each marker the same color, default is 'w' wolffd@0: % 'none' sets the marker fill invisible: only edges are shown wolffd@0: % (matrix) size N x 3, consisting of RGB triples as rows wolffd@0: % sets different color for each marker. This may be wolffd@0: % used to code the time series using color/grayscale. wolffd@0: % wolffd@0: % NOTE Markers '*','+','x', or '.' can't use MarkerColor wolffd@0: % since these objects have no face (fill) color: only wolffd@0: % EdgeColor matters for these markers. wolffd@0: % wolffd@0: % 'EdgeColor' see General Optional Input Arguments. Default is wolffd@0: % 'none' - except if MarkerColor is 'none' or Marker wolffd@0: % is 'x','*,'x', or '.'. In these cases default wolffd@0: % EdgeColor is 'white'. wolffd@0: % wolffd@0: % 'MarkerSize' The size of "comet core" and tail wolffd@0: % (vector) size 1 x 2: first element sets the size for the marker wolffd@0: % representing D(1) and the second set size for D(end) wolffd@0: % the size (area) of the markes between these changes linearly. wolffd@0: % Note that size units for 'lattice' marker style are wolffd@0: % normalized so that 1 means map unit size but for built-in wolffd@0: % marker styles the size is given points. wolffd@0: % wolffd@0: % Marker default value wolffd@0: % 'lattice' [0.8 0.1] wolffd@0: % 'o','v', etc. [20 4] wolffd@0: % wolffd@0: % OUTPUT ARGUMENTS wolffd@0: % wolffd@0: % h (vector) handles to all objects created by the function wolffd@0: % wolffd@0: % OBJECT TAGS wolffd@0: % wolffd@0: % Field Tag in every object is set to wolffd@0: % wolffd@0: % 'Lab' for objects created in mode 'label' wolffd@0: % 'Hit' -"- 'hit' wolffd@0: % 'Traj' -"- 'traj' wolffd@0: % 'Comet' -"- 'comet' wolffd@0: % wolffd@0: % EXAMPLES wolffd@0: % wolffd@0: % Not yet ready wolffd@0: % wolffd@0: % SEE ALSO wolffd@0: % wolffd@0: % som_show Basic map visualization wolffd@0: % som_show_clear Clear hit marks, labels or trajectories from current figure. 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 131199 wolffd@0: wolffd@0: %% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: error(nargchk(2,Inf,nargin)) % check no. of input args wolffd@0: wolffd@0: % Get data from the SOM_SHOW figure, exit if error wolffd@0: wolffd@0: [handles,msg,lattice,msize,dim]=vis_som_show_data('all',gcf); wolffd@0: error(msg); wolffd@0: wolffd@0: munits=prod(msize); wolffd@0: % Initialize some variables: these must exist later; wolffd@0: % the default values are set by subfunctions wolffd@0: wolffd@0: Property=init_properties; wolffd@0: Property.handles=handles; wolffd@0: wolffd@0: %%% Check mode and that D is of right type & size for that mode wolffd@0: % mode has to be string wolffd@0: if ~vis_valuetype(mode,{'string'}), wolffd@0: error('String value expected for first input argument (mode).'); wolffd@0: else wolffd@0: mode=lower(mode); % case insensitive wolffd@0: mode_=mode; % 'mode' is internal variable; wolffd@0: % for program constructs 'mode_' is shown to wolffd@0: % user in some error messags wolffd@0: end wolffd@0: wolffd@0: switch mode % check mode wolffd@0: case 'hit' wolffd@0: %%% Hit histogram visualization: vector [msize k] wolffd@0: wolffd@0: if ~vis_valuetype(D,{'nxm'}), wolffd@0: error('Hit visualization: a matrix expected for data input.'); wolffd@0: elseif size(D,1) ~= prod(msize) wolffd@0: error('Hit visualization: data and map size do not match.'); wolffd@0: end wolffd@0: % Multiple hit histograms wolffd@0: if size(D,2)>1 wolffd@0: mode='mhit'; wolffd@0: % Hit count musn't be negative wolffd@0: if any(D(:)<0), wolffd@0: error('Hit visualization: negative hit count in data not allowed!'); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: case {'traj','comet'} wolffd@0: %%% Trajectory like visualizations wolffd@0: wolffd@0: if ~vis_valuetype(D,{'nx1'}), wolffd@0: error('Trajectory/Comet: a Nx1 vector expected for data input.'); wolffd@0: elseif any(D>prod(msize))| any(D<1), wolffd@0: error('Trajectory/Comet: BMU indices out of range in data input.'); wolffd@0: elseif any(fix(D)~=D), wolffd@0: warning('Trajectory/Comet: BMU indices not integer. Rounding...'); wolffd@0: elseif size(D,1)<2 wolffd@0: error('At least two BMU indexes expected.'); wolffd@0: end wolffd@0: wolffd@0: case 'label' wolffd@0: %%% Label visualizations wolffd@0: wolffd@0: if isstruct(D), % check if D is a map wolffd@0: [tmp,ok,tmp]=som_set(D); wolffd@0: if all(ok) & strcmp(D.type,'som_map') wolffd@0: ; wolffd@0: else wolffd@0: error('Map struct is invalid!'); wolffd@0: end wolffd@0: % Size check wolffd@0: if length(msize) ~= length(D.topol.msize) | ... wolffd@0: munits ~= prod(D.topol.msize), wolffd@0: error(['The size of the input map and the map in the figure' ... wolffd@0: ' do not match.']); wolffd@0: end wolffd@0: D=D.labels; wolffd@0: % Cell input wolffd@0: elseif vis_valuetype(D,{'2Dcellarray_of_char'}) wolffd@0: ; wolffd@0: % Char input wolffd@0: elseif vis_valuetype(D,{'char_array'}), wolffd@0: D=cellstr(D); wolffd@0: else wolffd@0: error(['Labels has to be in a map struct or in a cell array' ... wolffd@0: ' of strings']); wolffd@0: end wolffd@0: if size(D,1) ~= munits wolffd@0: error(['The number of labels does not match the size of the map' ... wolffd@0: ' in the figure.']); wolffd@0: end wolffd@0: otherwise wolffd@0: error('Invalid visualization mode.'); wolffd@0: end wolffd@0: wolffd@0: if rem(length(varargin),2) wolffd@0: error('Mismatch in identifier-value pairs or wrong input argument order.'); wolffd@0: end wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % read in optional arguments wolffd@0: wolffd@0: for i=1:2:length(varargin), wolffd@0: %% Check that all argument types are strings wolffd@0: wolffd@0: if ~ischar(varargin{i}) wolffd@0: error('Invalid identifier name or input argument order.'); wolffd@0: end wolffd@0: wolffd@0: %% Lower/uppercase in identifier types doesn't matter: wolffd@0: wolffd@0: identifier=lower(varargin{i}); % identifier (lowercase) wolffd@0: value=varargin{i+1}; wolffd@0: wolffd@0: % Check property identifiers and values and store the values. wolffd@0: % Struct used_in is set to initiate warning messages: wolffd@0: % if a don't care propersty is set, the user is warned. wolffd@0: wolffd@0: switch identifier wolffd@0: case 'marker' wolffd@0: %%% Marker for hits or trajectories wolffd@0: switch mode wolffd@0: case 'mhit' wolffd@0: if vis_valuetype(value,{'markerstyle'}) | ... wolffd@0: (vis_valuetype(value,{'string'}) & ... wolffd@0: any(strcmp(value,{'lattice','pie'}))), wolffd@0: ; % ok wolffd@0: elseif vis_valuetype(value,{'cellcolumn_of_char'}), wolffd@0: if size(value,1) ~= size(D,2) wolffd@0: error([' If a cell of Markers is specified its size must be' ... wolffd@0: ' number_of_hit_histograms x 1.']); wolffd@0: else wolffd@0: for i=1:size(D,2), wolffd@0: if ~vis_valuetype(value{i},{'markerstyle'}) wolffd@0: error('Cell input for ''Marker'' contains invalid styles.') wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: else wolffd@0: error([' Invalid ''Marker'' in case of multiple hit histograms.' ... wolffd@0: char(10) ' See detailed documentation.']) wolffd@0: end wolffd@0: case {'comet','hit'} wolffd@0: if vis_valuetype(value,{'markerstyle'}) | isempty(value), wolffd@0: % ok; wolffd@0: elseif ischar(value) & strcmp(value,'lattice'), wolffd@0: % ok; wolffd@0: else wolffd@0: error(['Marker must be Matlab''s marker style, or string' ... wolffd@0: ' ''lattice''.']); wolffd@0: end wolffd@0: case 'traj' wolffd@0: if ~vis_valuetype(value,{'markerstyle'}) & ~isempty(value), wolffd@0: error('In mode ''traj'' Marker must be one of Matlab''s built-in marker styles'); wolffd@0: end wolffd@0: end wolffd@0: used_in.comet=1; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: case 'markersize' wolffd@0: %%% Marker for hits or trajectories wolffd@0: switch mode wolffd@0: case 'comet' wolffd@0: if ~vis_valuetype(value,{'1x2'}) & ~isempty(value), wolffd@0: error('In mode ''comet'' MarkerSize'' must be a 1x2 vector.'); wolffd@0: end wolffd@0: case {'hit','traj'} wolffd@0: if ~vis_valuetype(value,{'1x1'}) & ~isempty(value), wolffd@0: error(['In mode ''' mode_ ... wolffd@0: ''' ''MarkerSize'' must be a scalar.']); wolffd@0: end wolffd@0: end wolffd@0: used_in.comet=1; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: case 'sizefactor' wolffd@0: %%% Hit dependent size factor wolffd@0: switch mode wolffd@0: case 'traj' wolffd@0: if ~vis_valuetype(value,{'string'}) | ... wolffd@0: ~any(strcmp(value,{'hit', 'equal'})), wolffd@0: error(['In mode ''traj'' ''SizeFactor'' must be ' ... wolffd@0: 'string ''equal'' or ''hit''.']); wolffd@0: end wolffd@0: case 'mhit' wolffd@0: if ~vis_valuetype(value,{'string'}) | ... wolffd@0: ~any(strcmp(value,{'common', 'separate'})), wolffd@0: error(['In mode ''hit'' ''SizeFactor'' must be ' ... wolffd@0: 'string ''common'' or ''separate''.']); wolffd@0: end wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=0; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: case 'markercolor' wolffd@0: %%% Markercolor wolffd@0: switch mode wolffd@0: case 'comet' wolffd@0: if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ... wolffd@0: ~vis_valuetype(value,{'nx3rgb',[size(D,1) 3]},'all') & ... wolffd@0: ~isempty(value), wolffd@0: error(['MarkerColor in mode ''comet'' must be a ColorSpec,' ... wolffd@0: ' string ''none'' or Mx3 matrix of RGB triples.']); wolffd@0: end wolffd@0: case 'mhit' wolffd@0: if ~vis_valuetype(value,{[size(D,2) 3],'nx3rgb'},'all') & ... wolffd@0: ~vis_valuetype(value,{'colorstyle','1x3rgb'}), wolffd@0: error([' If multiple hit histograms in mode ''hit'' are' ... wolffd@0: char(10) ... wolffd@0: ' given MarkerColor must be ColorSpec or a Kx3 matrix' ... wolffd@0: char(10)... wolffd@0: ' of RGB triples where K is the number of histograms.']); wolffd@0: end wolffd@0: case 'hit' wolffd@0: if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ... wolffd@0: ~isempty(value), wolffd@0: error(['MarkerColor in mode ''hit'' ' ... wolffd@0: 'must be a ColorSpec or string ''none''.']); wolffd@0: end wolffd@0: case 'traj' wolffd@0: if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ... wolffd@0: ~isempty(value), wolffd@0: error(['MarkerColor in mode ''traj'' ' ... wolffd@0: 'must be a ColorSpec or string ''none''.']); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: used_in.comet=1; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: case 'edgecolor' wolffd@0: %%% Color for marker edges wolffd@0: if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ~isempty(value), wolffd@0: error('''EdgeColor'' must be a ColorSpec or string ''none''.') wolffd@0: end wolffd@0: wolffd@0: used_in.comet=1; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: case 'text' wolffd@0: %%% Labeling for trajectories/hits wolffd@0: switch mode wolffd@0: case 'hit' wolffd@0: %%% Hit count using numbers? wolffd@0: if isempty(value), wolffd@0: value='off'; wolffd@0: elseif vis_valuetype(value,{'string'}) & ... wolffd@0: ~any(strcmp(value,{'on','off'})), wolffd@0: error('Value for Text in mode ''hit'' should be ''on'' or ''off''.'); wolffd@0: else wolffd@0: ; % ok wolffd@0: end wolffd@0: %case 'traj','comet' wolffd@0: % if ~vis_valuetype(value,{'char_array','cellcolumn_of_char'}) & ... wolffd@0: % ~isempty(value) wolffd@0: % error('Value for Text is of wrong type or size.') wolffd@0: % elseif ischar(value) wolffd@0: % value=strcell(value) % ok, convert to cell wolffd@0: % end wolffd@0: % if size(traj_label,1)~=size(D,1) wolffd@0: % error(['The number of labels in Text and the length of the' ... wolffd@0: % ' trajectory do not match.']); wolffd@0: % end wolffd@0: case 'label' wolffd@0: ; % not used wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=0; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=0; wolffd@0: wolffd@0: case 'textsize' wolffd@0: %%% Text size for labels wolffd@0: wolffd@0: if ~vis_valuetype(value,{'1x1'}) & ~isempty(value), wolffd@0: error('TextSize must be scalar.'); wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=0; wolffd@0: used_in.label=1; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=0; wolffd@0: wolffd@0: case 'textcolor' wolffd@0: %%% Color for labels wolffd@0: wolffd@0: if ~vis_valuetype(value,{'colorstyle','1x3rgb','xor'}) & ~isempty(value), wolffd@0: error('''TextColor'' must be ColorSpec, ''xor'' or ''none''.') wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=0; wolffd@0: used_in.label=1; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=0; wolffd@0: wolffd@0: case 'trajwidth' wolffd@0: %%% Basic line width for a line trajectory wolffd@0: if ~vis_valuetype(value,{'1x1'}) & ~isempty(value), wolffd@0: error('TrajWidth must be a scalar.'); wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=0; wolffd@0: used_in.mhit=0; wolffd@0: wolffd@0: case 'widthfactor' wolffd@0: %%% Hit factor for a line trajectory wolffd@0: if ~vis_valuetype(value,{'string'}) | ... wolffd@0: ~any(strcmp(value,{'hit', 'equal'})), wolffd@0: error(['In mode ''traj'' ''WidthFactor'' must be ' ... wolffd@0: 'string ''equal'' or ''hit''.']); wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=0; wolffd@0: used_in.mhit=0; wolffd@0: wolffd@0: case 'trajcolor' wolffd@0: %%% Color for trajectory line wolffd@0: wolffd@0: if ~vis_valuetype(value,{'colorstyle','1x3rgb','xor'}) & ~isempty(value), wolffd@0: error('''TrajColor'' must be a ColorSpec or string ''xor''.') wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=0; wolffd@0: used_in.mhit=0; wolffd@0: wolffd@0: case 'uselabel' wolffd@0: %%% Which labels to show wolffd@0: error('Not yet implemented.'); wolffd@0: wolffd@0: case 'shift' wolffd@0: if ~vis_valuetype(value,{'1x1'}) | ((value < 0) | (value > 1)), wolffd@0: error('''Shift'' must be a scalar in range [0,1].') wolffd@0: end wolffd@0: used_in.comet=0; % Set relevance flags wolffd@0: used_in.traj=0; wolffd@0: used_in.label=0; wolffd@0: used_in.hit=0; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: case 'subplot' wolffd@0: %%% The subplots which are affected wolffd@0: wolffd@0: if vis_valuetype(value,{'1xn','nx1','string'}), wolffd@0: if ischar(value), wolffd@0: if ~strcmp(value,'all'), wolffd@0: error('Only valid string value for subplot indices is ''all''.'); wolffd@0: else wolffd@0: value=1:length(handles); wolffd@0: end wolffd@0: elseif any(value<1) | any(value>length(handles)), wolffd@0: error('Subplot indices must be in range 1...number_of_subplots!'); wolffd@0: end wolffd@0: elseif ~isempty(value) wolffd@0: error('Invalid subplot indices!'); wolffd@0: end wolffd@0: used_in.comet=1; % Set relevance flags wolffd@0: used_in.traj=1; wolffd@0: used_in.label=1; wolffd@0: used_in.hit=1; wolffd@0: used_in.mhit=1; wolffd@0: wolffd@0: otherwise wolffd@0: error([ 'Unknown identifier ''' identifier '''.']); wolffd@0: end wolffd@0: wolffd@0: % Warn user if the property that was set has no effect in the wolffd@0: % selected visuzlization mode wolffd@0: wolffd@0: if ~getfield(used_in, mode), wolffd@0: warning(['Property ''' identifier ''' has no effect in mode ''' ... wolffd@0: mode_ '''.']); wolffd@0: else wolffd@0: Property=setfield(Property,identifier,value); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % set default subplot wolffd@0: if isempty(Property.subplot) wolffd@0: % search the subplot number for current axis wolffd@0: value=find(gca==handles); wolffd@0: if isempty(value) | value>length(handles) wolffd@0: error('SubPlot default value setting: current axis is not in the figure!'); wolffd@0: else wolffd@0: Property.subplot=value; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %%%%%%% Main switch: select the right subfunction %%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: switch mode wolffd@0: case 'hit' wolffd@0: h_=hit(D, lattice, msize, Property); wolffd@0: case 'mhit' wolffd@0: h_=mhit(D, lattice, msize, Property); wolffd@0: case 'label' wolffd@0: h_=label(D, lattice, msize, Property); wolffd@0: case 'traj' wolffd@0: h_=traj(D, lattice, msize, Property); wolffd@0: case 'comet' wolffd@0: %error('Not yet implemented.'); wolffd@0: h_=comet(D, lattice, msize, Property); wolffd@0: otherwise wolffd@0: error('Whoops! Internal error: unknown mode!'); wolffd@0: end wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% Build output if necessary %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: if nargout>0 wolffd@0: h=h_; wolffd@0: end wolffd@0: wolffd@0: %%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: function h_=hit(Hits, lattice, msize, Property); wolffd@0: wolffd@0: % number of map units wolffd@0: munits=prod(msize); wolffd@0: wolffd@0: % subplots wolffd@0: p=Property.subplot; wolffd@0: handles=Property.handles; wolffd@0: wolffd@0: % Set default marker wolffd@0: if isempty(Property.marker), wolffd@0: if strcmp(Property.text,'on') wolffd@0: Property.marker='none'; wolffd@0: else wolffd@0: Property.marker='lattice'; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Set default markersize wolffd@0: if isempty(Property.markersize) wolffd@0: if strcmp(Property.marker,'none'), wolffd@0: warning('MarkerSize is not meaningful since Marker is set to ''none''.'); wolffd@0: elseif strcmp(Property.marker,'lattice'), wolffd@0: Property.markersize=1; % normalized size wolffd@0: else wolffd@0: Property.markersize=12; % points wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Set default colors wolffd@0: if ~isempty(Property.markercolor), wolffd@0: if strcmp(Property.marker,'none') wolffd@0: warning('MarkerColor is not used since Marker is set to ''none''.'); wolffd@0: Property.markercolor=[]; % not used wolffd@0: else wolffd@0: ; % ok wolffd@0: end wolffd@0: elseif any(strcmp(Property.marker,{'+','*','.','x'})), wolffd@0: % these don't use fill color: 'none' will cause default wolffd@0: % edgecolor to be 'k'. wolffd@0: Property.markercolor='none'; wolffd@0: else wolffd@0: Property.markercolor='k'; wolffd@0: end wolffd@0: wolffd@0: if ~isempty(Property.edgecolor), wolffd@0: if strcmp(Property.marker,'none') wolffd@0: warning(['EdgeColor is not used since Marker is set to' ... wolffd@0: ' ''none''.']); wolffd@0: else wolffd@0: ; %ok wolffd@0: end wolffd@0: elseif ~strcmp(Property.markercolor,'none'), wolffd@0: Property.edgecolor='none'; wolffd@0: else wolffd@0: Property.edgecolor='k'; wolffd@0: end wolffd@0: wolffd@0: % Set default text wolffd@0: if isempty(Property.text), wolffd@0: Property.text='off'; wolffd@0: end wolffd@0: wolffd@0: % Set default textsize wolffd@0: if isempty(Property.textsize) wolffd@0: Property.textsize=10; wolffd@0: elseif strcmp(Property.text,'off') wolffd@0: warning('TextSize not used as hits are not set to be shown as numbers.'); wolffd@0: end wolffd@0: wolffd@0: % Set default textcolor wolffd@0: if isempty(Property.textcolor) wolffd@0: Property.textcolor='w'; wolffd@0: elseif strcmp(Property.text,'off') wolffd@0: warning('TextColor not used as hits are not set to be shown as numbers.'); wolffd@0: end wolffd@0: wolffd@0: %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: h_=[]; % this variable is for collecting the object handles wolffd@0: wolffd@0: % Select the drawing mode wolffd@0: wolffd@0: if ~strcmp(Property.marker,'none') wolffd@0: wolffd@0: %%%%% Draw spots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: % unit coordinates wolffd@0: coord=som_vis_coords(lattice,msize); wolffd@0: wolffd@0: % Calculate the size of the spots wolffd@0: mx=max(Hits); wolffd@0: wolffd@0: if mx==0, wolffd@0: % nothing to draw! wolffd@0: h_=[]; wolffd@0: return wolffd@0: else wolffd@0: Size=sqrt(Hits./mx); wolffd@0: end wolffd@0: % coordinates for non-zero hits (only those are drawn) wolffd@0: coord=coord(Size~=0,:); wolffd@0: Size=Size(Size~=0); wolffd@0: N=size(Size,1); wolffd@0: wolffd@0: % som_cplane can't draw one unit with arbitrary wolffd@0: % coordinates as it its mixed with msize: wolffd@0: if size(coord,1)==1 & strcmp(Property.marker,'lattice'), wolffd@0: Size=[Size;Size]; wolffd@0: coord=[coord;coord]; wolffd@0: end wolffd@0: wolffd@0: for i=1:length(p), wolffd@0: % Set axes wolffd@0: axes(handles(p(i))); wolffd@0: % Get hold state and caxis wolffd@0: memhold=ishold; cax=caxis; wolffd@0: hold on; wolffd@0: wolffd@0: switch Property.marker wolffd@0: case 'lattice' wolffd@0: h_(i,1)=som_cplane(lattice, coord, Property.markercolor, ... wolffd@0: Property.markersize*Size); wolffd@0: otherwise wolffd@0: [S,m]=som_grid(lattice, [N 1],... wolffd@0: 'Coord',coord, ... wolffd@0: 'Line','none',... wolffd@0: 'Marker',Property.marker,... wolffd@0: 'MarkerColor',Property.markercolor,... wolffd@0: 'MarkerSize', Size*Property.markersize); wolffd@0: h_=[h_;m(:)]; wolffd@0: end wolffd@0: wolffd@0: % Restore hold state wolffd@0: if ~memhold wolffd@0: hold off; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Set edgecolor wolffd@0: if strcmp(Property.marker,'lattice') wolffd@0: set(h_,'edgecolor',Property.edgecolor); wolffd@0: else wolffd@0: set(h_,'markeredgecolor',Property.edgecolor); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: if strcmp(Property.text,'on'), wolffd@0: %%%%% Draw numbers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: % Do numbers wolffd@0: Hits=reshape(Hits,[munits 1]); wolffd@0: labels=cell([munits 1]); wolffd@0: for i=1:length(Hits) wolffd@0: if Hits(i) % zero hit won't be shown wolffd@0: labels(i)={num2str(Hits(i))}; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: for i=1:length(p), wolffd@0: axes(handles(p(i))); % Set axes wolffd@0: memhold=ishold; % Get hold state wolffd@0: hold on; wolffd@0: [S,m,l,t]=som_grid(lattice, msize, ... wolffd@0: 'Line','none',... wolffd@0: 'Marker','none', ... wolffd@0: 'Label',labels, ... wolffd@0: 'LabelColor', Property.textcolor, ... wolffd@0: 'LabelSize', Property.textsize); wolffd@0: % Get handles wolffd@0: h_=[h_;t(:)]; wolffd@0: wolffd@0: % Restore hold state and caxis wolffd@0: if ~memhold wolffd@0: hold off; wolffd@0: end wolffd@0: caxis(cax); wolffd@0: end wolffd@0: wolffd@0: % Remove zero object handles (missing objects) wolffd@0: h_=setdiff(h_,0); wolffd@0: end wolffd@0: wolffd@0: %% Set object tags (for som_show_clear) %%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: set(h_,'Tag','Hit') wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: function h_=mhit(Hits, lattice, msize, Property); wolffd@0: wolffd@0: % number of map units wolffd@0: munits=prod(msize); wolffd@0: wolffd@0: % subplots wolffd@0: p=Property.subplot; wolffd@0: handles=Property.handles; wolffd@0: wolffd@0: wolffd@0: % Set default marker wolffd@0: if isempty(Property.marker), wolffd@0: Property.marker=lattice; wolffd@0: end wolffd@0: wolffd@0: % variable 'mode' indicates which kind of markers are used: wolffd@0: wolffd@0: if iscell(Property.marker), wolffd@0: mode='marker'; wolffd@0: elseif vis_valuetype(Property.marker,{'markerstyle'}), wolffd@0: mode='marker'; wolffd@0: elseif strcmp(Property.marker,'pie'), wolffd@0: mode='pie'; wolffd@0: else wolffd@0: mode='lattice'; wolffd@0: end wolffd@0: wolffd@0: % Set default size scaling wolffd@0: if isempty(Property.sizefactor) wolffd@0: Property.sizefactor='separate'; wolffd@0: end wolffd@0: wolffd@0: % Set default markersize wolffd@0: if isempty(Property.markersize) wolffd@0: if any(strcmp(mode,{'lattice','pie'})), wolffd@0: Property.markersize=1; % normalized wolffd@0: else wolffd@0: Property.markersize=12; % points wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Set default colors wolffd@0: wolffd@0: if isempty(Property.markercolor), wolffd@0: Property.markercolor=hsv(size(Hits,2)); wolffd@0: end wolffd@0: wolffd@0: if isempty(Property.edgecolor), wolffd@0: if vis_valuetype(Property.markercolor,{'none'}), wolffd@0: Property.edgecolor='k'; wolffd@0: else wolffd@0: Property.edgecolor='none'; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Set default shift wolffd@0: if isempty(Property.shift) wolffd@0: Property.shift=0; wolffd@0: end wolffd@0: wolffd@0: %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: h_=[]; % this variable is for collecting the object handles wolffd@0: wolffd@0: switch mode wolffd@0: case {'marker','lattice'} wolffd@0: % Number of hits histograms wolffd@0: n_Hits=size(Hits,2); wolffd@0: % Calculate the size of the spots wolffd@0: wolffd@0: if strcmp(Property.sizefactor,'common') wolffd@0: mx=max(max(Hits)); wolffd@0: if mx==0 % nothing to draw! wolffd@0: h_=[]; return wolffd@0: end wolffd@0: spotSize=sqrt(Hits./mx); wolffd@0: else wolffd@0: mx=repmat(max(Hits),munits,1); wolffd@0: mx(mx==0)=1; % Prevent division by zero wolffd@0: spotSize=sqrt(Hits./mx); wolffd@0: end wolffd@0: wolffd@0: %%% Make spotSize wolffd@0: wolffd@0: %reshape Size to a vector [spotSizeforHist(:,1); spotSizeforHist(:,2);...] wolffd@0: spotSize=spotSize(:); wolffd@0: wolffd@0: % indices for non-zero hits (only those are drawn) wolffd@0: notZero=find(spotSize ~= 0); wolffd@0: wolffd@0: % Drop zeros away from spotSize wolffd@0: spotSize=spotSize(notZero); wolffd@0: wolffd@0: % Order spots so that bigger will be drawn first, so that they wolffd@0: % won't hide smaller ones wolffd@0: [dummy, sizeOrder]=sort(spotSize); sizeOrder=sizeOrder(end:-1:1); wolffd@0: spotSize=spotSize(sizeOrder); wolffd@0: wolffd@0: %%% Make unit coordinates wolffd@0: coord=som_vis_coords(lattice,msize); wolffd@0: wolffd@0: move=repmat(linspace(-.1,.1,n_Hits),size(coord,1),1)*Property.shift; wolffd@0: move=repmat(move(:),1,2); wolffd@0: wolffd@0: % do n_Hits copies of unit coordinates so that they match spotSize wolffd@0: coord=repmat(coord,n_Hits,1)+move; wolffd@0: wolffd@0: % Drop zeros away from coords and order wolffd@0: coord=coord(notZero,:); wolffd@0: coord=coord(sizeOrder,:); wolffd@0: wolffd@0: %%% Make unit colors wolffd@0: wolffd@0: if vis_valuetype(Property.markercolor,{'nx3'}), wolffd@0: % If multiple colors Copy unit colors so that they match spotSize wolffd@0: color=Property.markercolor(reshape(repmat([1:n_Hits]',1,munits)',... wolffd@0: munits*n_Hits,1),:); wolffd@0: % drop zeros away & order wolffd@0: color=color(notZero,:); wolffd@0: color=color(sizeOrder,:); wolffd@0: else wolffd@0: % only on color wolffd@0: color=Property.markercolor; wolffd@0: end wolffd@0: wolffd@0: %%% Make unit markers wolffd@0: wolffd@0: if iscell(Property.marker), wolffd@0: %marker shows class: wolffd@0: marker=char(Property.marker); wolffd@0: marker=marker(reshape(repmat([1:n_Hits]',1,munits)',... wolffd@0: munits*n_Hits,1),:); wolffd@0: % Drop zeros, order & make to cell array (for som_grid) wolffd@0: marker=marker(notZero,:); wolffd@0: marker=cellstr(marker(sizeOrder,:)); wolffd@0: else wolffd@0: marker=Property.marker; wolffd@0: end wolffd@0: wolffd@0: % som_cplane can't draw one unit with arbitrary wolffd@0: % coordinates as it its mixed with msize: wolffd@0: if size(coord,1)==1 & strcmp(mode,'lattice'), wolffd@0: spotSize = [spotSize; spotSize]; wolffd@0: coord = [coord; coord]; wolffd@0: end wolffd@0: wolffd@0: N=length(notZero); % for som_grid visuzalization routine wolffd@0: case 'pie' wolffd@0: % marker 'pie' requires size parameter totHits wolffd@0: if strcmp(mode,'pie') wolffd@0: coord=som_vis_coords(lattice, msize); wolffd@0: notZero=sum(Hits,2)>0; wolffd@0: Hits=Hits(notZero,:); wolffd@0: coord=coord(notZero,:); wolffd@0: N=size(notZero,1); wolffd@0: totHits=sqrt(sum(Hits,2)./max(sum(Hits,2))); wolffd@0: end wolffd@0: wolffd@0: % som_pieplane can't draw one unit with arbitrary wolffd@0: % coordinates as it its mixed with msize: wolffd@0: if size(coord,1)==1, wolffd@0: Hits= [Hits; Hits]; wolffd@0: coord = [coord; coord]; wolffd@0: end wolffd@0: otherwise wolffd@0: error('Whoops: internal error. Bad mode in subfunction mhit'); wolffd@0: end wolffd@0: wolffd@0: for i=1:length(p), %%% Main loop begins wolffd@0: % Set axis wolffd@0: axes(handles(p(i))); wolffd@0: % Get hold state and caxis wolffd@0: memhold=ishold; cax=caxis; wolffd@0: hold on; wolffd@0: wolffd@0: switch mode wolffd@0: case 'lattice' wolffd@0: h_(i,1)=som_cplane(lattice, coord, color, spotSize*Property.markersize); wolffd@0: case 'marker' wolffd@0: [S,m]=som_grid(lattice, [N 1],... wolffd@0: 'Coord',coord, ... wolffd@0: 'Line','none',... wolffd@0: 'Marker',marker,... wolffd@0: 'MarkerColor',color,... wolffd@0: 'MarkerSize', spotSize*Property.markersize); wolffd@0: h_=[h_;m(:)]; wolffd@0: case 'pie' wolffd@0: h_(i)=som_pieplane(lattice, coord, ... wolffd@0: Hits, Property.markercolor, ... wolffd@0: totHits*Property.markersize); wolffd@0: end wolffd@0: wolffd@0: % Restore hold state and caxis wolffd@0: if ~memhold wolffd@0: hold off; wolffd@0: end wolffd@0: caxis(cax); wolffd@0: end wolffd@0: wolffd@0: % Set edgecolor wolffd@0: if any(strcmp(mode,{'lattice','pie'})), wolffd@0: set(h_,'edgecolor',Property.edgecolor); wolffd@0: else wolffd@0: set(h_,'markeredgecolor',Property.edgecolor); wolffd@0: end wolffd@0: wolffd@0: %% Set object tags (for som_show_clear) %%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: set(h_,'Tag','Hit') wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: function h_=label(Labels, lattice, msize, Property) wolffd@0: wolffd@0: % number of map units wolffd@0: munits=prod(msize); wolffd@0: wolffd@0: % subplots and handles wolffd@0: p=Property.subplot; wolffd@0: handles= Property.handles; wolffd@0: wolffd@0: % Set default text size wolffd@0: if isempty(Property.textsize) % default point size wolffd@0: Property.textsize=10; wolffd@0: end wolffd@0: wolffd@0: % Check color/set default wolffd@0: if isempty(Property.textcolor), wolffd@0: Property.textcolor='k'; wolffd@0: end wolffd@0: wolffd@0: % handles will be collected in h_ for output wolffd@0: h_=[]; wolffd@0: wolffd@0: %%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: for i=1:length(p); wolffd@0: % set axes wolffd@0: axes(handles(p(i))); wolffd@0: % store hold state and caxis (for some reason matlab may wolffd@0: % change caxis(!?) wolffd@0: memhold=ishold; wolffd@0: hold on; wolffd@0: cax=caxis; wolffd@0: wolffd@0: % Write labels wolffd@0: [S,m,l,t]=som_grid(lattice, msize, ... wolffd@0: 'Line','none', ... wolffd@0: 'Marker', 'none', ... wolffd@0: 'Label', Labels, ... wolffd@0: 'LabelColor', Property.textcolor, ... wolffd@0: 'LabelSize', Property.textsize); wolffd@0: % Get handles wolffd@0: h_=[h_;m(:);l(:);t(:)]; wolffd@0: wolffd@0: % reset hold state and caxis wolffd@0: if ~memhold wolffd@0: hold off; wolffd@0: end wolffd@0: caxis(cax); wolffd@0: end wolffd@0: wolffd@0: %%% Set object tags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: set(h_,'Tag','Lab'); wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: function h_=traj(bmu, lattice, msize, Property) wolffd@0: wolffd@0: % number of map units wolffd@0: munits=prod(msize); wolffd@0: wolffd@0: % subplots and handles wolffd@0: p=Property.subplot; wolffd@0: handles=Property.handles; wolffd@0: wolffd@0: % Set default text color wolffd@0: %if isempty(Property.textcolor), wolffd@0: % Property.textcolor='k'; wolffd@0: %end wolffd@0: wolffd@0: % Set default text size wolffd@0: %if isempty(Property.textsize) wolffd@0: % Property.textsize=10; wolffd@0: %end wolffd@0: wolffd@0: % Set default marker wolffd@0: if isempty(Property.marker) wolffd@0: Property.marker='o'; wolffd@0: end wolffd@0: wolffd@0: % Set default markersize wolffd@0: if isempty(Property.markersize) wolffd@0: Property.markersize=10; wolffd@0: end wolffd@0: wolffd@0: % Set default markercolor wolffd@0: if isempty(Property.markercolor) wolffd@0: Property.markercolor='w'; wolffd@0: end wolffd@0: wolffd@0: % Set default sizefactor wolffd@0: if isempty(Property.sizefactor) wolffd@0: %Property.sizefactor=0; wolffd@0: Property.sizefactor='hit'; wolffd@0: end wolffd@0: wolffd@0: % Set default trajwidth wolffd@0: if isempty(Property.trajwidth) wolffd@0: Property.trajwidth=3; wolffd@0: end wolffd@0: wolffd@0: % Set default widthfactor wolffd@0: if isempty(Property.widthfactor) wolffd@0: Property.widthfactor='hit'; wolffd@0: end wolffd@0: wolffd@0: % Set default trajcolor wolffd@0: if isempty(Property.trajcolor) wolffd@0: Property.trajcolor='w'; wolffd@0: end wolffd@0: wolffd@0: % if no labels, do a empty cell array for syntax reasons wolffd@0: %if isempty(Property.text), wolffd@0: % Property.text=cell(munits,1); wolffd@0: %end wolffd@0: wolffd@0: h_=[]; % handles will be collected in h_ for output wolffd@0: l=length(bmu); % length of trajectory wolffd@0: C=sparse(munits, munits); % init a connection matrix wolffd@0: wolffd@0: %%%%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: % Calculate the connection matrix that describes the trajectory wolffd@0: for i=1:l-1, wolffd@0: % The following if structure removes the possible redundancy due wolffd@0: % to travels in both directions between two nodes of trajectory wolffd@0: % (i.e. reflexivity) wolffd@0: I=bmu(i+1);J=bmu(i); wolffd@0: %if bmu(i)>bmu(i+1) wolffd@0: wolffd@0: %else wolffd@0: % I=bmu(i);J=bmu(i+1); wolffd@0: %end wolffd@0: C(I,J)=C(I,J)+1; wolffd@0: end wolffd@0: wolffd@0: % transitive connections are equal wolffd@0: C=C+C'; wolffd@0: % drop reflexive conncetions away wolffd@0: C=spdiags(zeros(munits,1),0,C); wolffd@0: wolffd@0: % Do labels of trajectory nodes wolffd@0: wolffd@0: %traj_lab=cell(munits,1); wolffd@0: hits=zeros(munits,1); wolffd@0: wolffd@0: for i=1:l, wolffd@0: % traj_lab{bmu(i)}=strvcat(traj_lab{bmu(i)},Property.text{i}); wolffd@0: hits(bmu(i))=(hits(bmu(i))+1); wolffd@0: end wolffd@0: wolffd@0: % Calculate unit coordinates wolffd@0: unit_coord=som_vis_coords(lattice, msize); wolffd@0: wolffd@0: % Calculate line width wolffd@0: if strcmp(Property.widthfactor,'equal') wolffd@0: TrajWidth=(C>0)*Property.trajwidth; wolffd@0: else wolffd@0: TrajWidth=Property.trajwidth.*sqrt(C./max(max(C))); wolffd@0: end wolffd@0: wolffd@0: % Calculate marker sizes wolffd@0: if strcmp(Property.sizefactor,'hit') wolffd@0: MarkerSize=Property.markersize*sqrt(hits/max(hits)); wolffd@0: else wolffd@0: MarkerSize=Property.markersize*(hits>0); wolffd@0: end wolffd@0: wolffd@0: for i=1:length(p), wolffd@0: axes(handles(p(i))); wolffd@0: % Get hold state and caxis wolffd@0: memhold=ishold; cax=caxis; wolffd@0: hold on; wolffd@0: wolffd@0: %'Label', traj_lab, ... wolffd@0: %'LabelColor', Property.textcolor, ... wolffd@0: %'LabelSize', Property.textsize, ... wolffd@0: wolffd@0: % Draw wolffd@0: [S,m,l,t,s]=som_grid(C,msize,'coord',unit_coord,... wolffd@0: 'Line','-', ... wolffd@0: 'LineColor', Property.trajcolor, ... wolffd@0: 'LineWidth', TrajWidth, ... wolffd@0: 'Marker', Property.marker, ... wolffd@0: 'MarkerColor', Property.markercolor, ... wolffd@0: 'MarkerSize', MarkerSize); wolffd@0: wolffd@0: % Restore hold state and caxis wolffd@0: if ~memhold wolffd@0: hold off; wolffd@0: end wolffd@0: caxis(cax); wolffd@0: % Get handles wolffd@0: h_=[h_;m(:);l(:);t(:);s(:)]; wolffd@0: end wolffd@0: wolffd@0: %% Set object tags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: set(h_,'Tag','Traj'); wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: function h_=comet(bmu, lattice, msize, Property) wolffd@0: wolffd@0: % number of map units wolffd@0: munits=prod(msize); wolffd@0: wolffd@0: % subplots and handles wolffd@0: p=Property.subplot; wolffd@0: handles=Property.handles; wolffd@0: wolffd@0: % Set default text color wolffd@0: %if isempty(Property.textcolor), wolffd@0: % Property.textcolor='k'; wolffd@0: %end wolffd@0: wolffd@0: %% Set default text size wolffd@0: %if isempty(Property.textsize) wolffd@0: % Property.textsize=10; wolffd@0: %end wolffd@0: wolffd@0: % Set default marker wolffd@0: if isempty(Property.marker) wolffd@0: Property.marker='o'; wolffd@0: end wolffd@0: wolffd@0: % Set default markersize wolffd@0: if isempty(Property.markersize), wolffd@0: if strcmp(Property.marker,'lattice'), wolffd@0: Property.markersize=linspace(0.8,0.1,length(bmu))'; wolffd@0: else wolffd@0: Property.markersize=sqrt(linspace(400,16,length(bmu)))'; wolffd@0: end wolffd@0: else wolffd@0: if strcmp(Property.marker,'lattice'), wolffd@0: Property.markersize=linspace(Property.markersize(1),... wolffd@0: Property.markersize(2), ... wolffd@0: length(bmu))'; wolffd@0: else wolffd@0: Property.markersize=sqrt(linspace(Property.markersize(1).^2,... wolffd@0: Property.markersize(2).^2, ... wolffd@0: length(bmu)))'; wolffd@0: wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % Set default markercolor wolffd@0: if isempty(Property.markercolor) wolffd@0: Property.markercolor='w'; wolffd@0: end wolffd@0: wolffd@0: % Set default edgecolor wolffd@0: if isempty(Property.edgecolor), wolffd@0: if vis_valuetype(Property.markercolor,{'nx3rgb'}), wolffd@0: Property.edgecolor='none'; wolffd@0: else wolffd@0: Property.edgecolor=Property.markercolor; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: h_=[];l_=[]; % handles will be collected in h_ for output wolffd@0: N_bmus=length(bmu); % length of trajectory wolffd@0: wolffd@0: % if no labels, do a empty cell array for syntax reasons wolffd@0: %if isempty(Property.text), wolffd@0: % Property.text=cell(N_bmus,1); wolffd@0: %end wolffd@0: wolffd@0: %%%%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: % Calculate unit coordinates for trajectory points wolffd@0: unit_coord=som_vis_coords(lattice, msize); wolffd@0: coord=unit_coord(bmu,:); wolffd@0: wolffd@0: % Make labels for the _unique_ units that the comet hits wolffd@0: wolffd@0: unique_bmu=unique(bmu); % count units wolffd@0: %N_labels=length(unique_bmu); wolffd@0: %traj_lab=cell(N_labels,1); % cell for labels wolffd@0: %label_coord=unit_coord(unique_bmu,:); % label coordinates wolffd@0: wolffd@0: % Make labels wolffd@0: %for i=1:N_bmus, wolffd@0: % index=find(unique_bmu==bmu(i)); wolffd@0: % traj_lab{index}=strvcat(traj_lab{index},Property.text{i}); wolffd@0: %end wolffd@0: wolffd@0: %Main loop for drawing comets wolffd@0: for i=1:length(p), wolffd@0: % set axis wolffd@0: axes(handles(p(i))); wolffd@0: wolffd@0: % Get hold state and caxis wolffd@0: memhold=ishold; cax=caxis; wolffd@0: hold on; wolffd@0: wolffd@0: if strcmp(Property.marker,'lattice'), wolffd@0: % Draw: marker is a patch ('hexa','rect') wolffd@0: l_=som_cplane(lattice, coord, Property.markercolor, ... wolffd@0: Property.markersize); wolffd@0: wolffd@0: % Set edgecolor wolffd@0: set(l_,'edgecolor',Property.edgecolor); wolffd@0: else wolffd@0: % Draw: other markers than 'hexa' or 'rect' wolffd@0: [S,m,l,t,s]=som_grid(lattice, [N_bmus 1], 'coord', coord,... wolffd@0: 'Line','none', ... wolffd@0: 'Marker', Property.marker, ... wolffd@0: 'MarkerColor', Property.markercolor, ... wolffd@0: 'MarkerSize',Property.markersize); wolffd@0: wolffd@0: % Set edgecolor wolffd@0: set(m, 'markeredgecolor', Property.edgecolor); wolffd@0: wolffd@0: % Get handles from markers wolffd@0: h_=[h_;l_(:);m(:);l(:);t(:);s(:)]; wolffd@0: end wolffd@0: wolffd@0: % Set labels wolffd@0: %[S,m,l,t,s]=som_grid(lattice, [N_labels 1], 'coord', label_coord,... wolffd@0: % 'Marker','none','Line','none',... wolffd@0: % 'Label', traj_lab, ... wolffd@0: % 'LabelColor', Property.textcolor, ... wolffd@0: % 'LabelSize', Property.textsize); wolffd@0: % Get handles from labels wolffd@0: %h_=[h_;m(:);l(:);t(:);s(:)]; wolffd@0: wolffd@0: % Restore hold state and caxis wolffd@0: if ~memhold wolffd@0: hold off; wolffd@0: end wolffd@0: caxis(cax); wolffd@0: end wolffd@0: wolffd@0: %% Set object tags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: set(h_,'Tag','Comet'); wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: wolffd@0: function P=init_properties; wolffd@0: wolffd@0: % Initialize an empty property struct wolffd@0: wolffd@0: P.marker=[]; wolffd@0: P.markersize=[]; wolffd@0: P.sizefactor=[]; wolffd@0: P.markercolor=[]; wolffd@0: P.edgecolor=[]; wolffd@0: P.trajwidth=[]; wolffd@0: P.widthfactor=[]; wolffd@0: P.trajcolor=[]; wolffd@0: P.text=[]; wolffd@0: P.textsize=[]; wolffd@0: P.textcolor=[]; wolffd@0: P.subplot=[]; wolffd@0: P.shift=[];