wolffd@0: function color = som_normcolor(data, clrmap) wolffd@0: wolffd@0: %SOM_NORMCOLOR RGB values of indexed colors for a given dataset and colormap wolffd@0: % wolffd@0: % color = som_normcolor(data, [clrmap]) wolffd@0: % wolffd@0: % color = som_normcolor(data); wolffd@0: % color = som_normcolor(data,jet(64)); wolffd@0: % wolffd@0: % Input and output arguments ([]'s are optional): wolffd@0: % data (struct) map or data struct wolffd@0: % (matrix) size N x dim wolffd@0: % [clrmap] (matrix) size N x 3, a valid colormap (an RGB value matrix) wolffd@0: % Default is current colormap. See COLORMAP. wolffd@0: % wolffd@0: % color (matrix) size N x 3 x dim, RGB matrix wolffd@0: % wolffd@0: % Purpose of this function is to calculate fixed RGB colors that are similar wolffd@0: % to indexed colors with the specified colormap. This is because some wolffd@0: % SOM Toolbox visualization functions (as SOM_GRID) do not use indexed colors wolffd@0: % if the underlying Matlab function (e.g. PLOT) do not use indexed colors wolffd@0: % wolffd@0: % EXAMPLE wolffd@0: % wolffd@0: % %%% Visualize three variables in a map using som_grid: wolffd@0: % %%% Give coordinates for the markers according to variables 1 and 2, and wolffd@0: % %%% 'indexed colors' according to variable 3. wolffd@0: % wolffd@0: % som_grid(map.topol.lattice,map.topol.msize,'Coord',map.codebook(:,1:2), ... wolffd@0: % 'markercolor', som_normcolor(map.codebook(:,3))); wolffd@0: wolffd@0: % Contributed to SOM Toolbox 2.0, February 11th, 2000 by Johan Himberg wolffd@0: % Copyright (c) by Johan Himberg wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % juha 150799 johan 010999 wolffd@0: wolffd@0: %%%% check possible errors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: error(nargchk(1,2,nargin)); wolffd@0: wolffd@0: if nargin < 2| isempty(clrmap), wolffd@0: clrmap=colormap; wolffd@0: elseif ~vis_valuetype(clrmap,{'nx3rgb'}), wolffd@0: error('The specified colormap is invalid!'); wolffd@0: end wolffd@0: wolffd@0: d=size(clrmap,1); wolffd@0: wolffd@0: if isstruct(data), wolffd@0: m_names={'type';'codebook';'topol';'labels';'neigh';'mask';'trainhist';... wolffd@0: 'name';'comp_names';'comp_norm'}; wolffd@0: d_names=fieldnames(vis_struct); wolffd@0: if length(fieldnames(data)) ~= length(d_names) % data is not som_data_struct wolffd@0: if length(fieldnames(data)) ~= length(m_names) % and not som_map_struct wolffd@0: error('Input argument is not a ''som_vis'' or ''som_map'' struct.') wolffd@0: elseif ~all(strcmp(fieldnames(data),m_names)) wolffd@0: error('Input argument is not a ''som_vis'' or ''som_map'' struct.') wolffd@0: else wolffd@0: data=data.codebook; wolffd@0: end wolffd@0: elseif ~all(strcmp(fieldnames(data),dnames)) wolffd@0: error('Input argument is not a ''som_vis'' or ''som_map'' struct.') wolffd@0: else wolffd@0: data=data.data; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: if ~isnumeric(data) | ndims(data) ~= 2 wolffd@0: error('Data is not 2 dimensional numeric matrix.'); wolffd@0: end wolffd@0: wolffd@0: %%% action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: data=som_normalize(data,'range'); wolffd@0: wolffd@0: for i=1:size(data,2), wolffd@0: inds=~isnan(data(:,i)); wolffd@0: color(inds,:,i)=clrmap(round(data(inds,i)*(d-1))+1,:); wolffd@0: color(~inds,:,i)=NaN; wolffd@0: end wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: