📄 som_show.m
字号:
h_axes(i,1)=subplot(x,y,i); % open a new subplot % Main switch: select function according to the flags set in comps switch Plane{i}.mode case 'comp' %%% Component plane tmp_h=som_cplane(lattice,msize, sMap.codebook(:,General.comp(i)), ... General.size); set(tmp_h,'EdgeColor', General.edgecolor); set(h_axes(i),'Tag','Cplane'); h_label(i,1)=xlabel(sMap.comp_names{General.comp(i)}); case 'compi' %%% Component plane (interpolated shading) tmp_h=som_grid(lattice, msize, 'surf', sMap.codebook(:,Plane{i}.value), ... 'Marker', 'none', 'Line', 'none'); set(h_axes(i),'Tag','CplaneI'); h_label(i,1)=xlabel(sMap.comp_names(Plane{i}.value)); vis_PlaneAxisProperties(gca,lattice,msize,NaN); case 'color' %%% Color plane tmp_h=som_cplane(lattice,msize,Plane{i}.value,General.size); set(tmp_h,'EdgeColor','none'); set(h_axes(i),'Tag','Cplane'); h_label(i,1)=xlabel(Plane{i}.name); case 'colori' %%% Color plane (interpolated shading) tmp_h=som_grid(lattice, msize, 'surf', Plane{i}.value, 'Marker', 'none', ... 'Line', 'none'); set(h_axes(i),'Tag','CplaneI'); h_label(i,1)=xlabel(Plane{i}.name); vis_PlaneAxisProperties(gca,lattice,msize,NaN); case 'empty' %%% Empty plane tmp_h=som_cplane(lattice,msize,'none'); h_label(i,1)=xlabel(Plane{i}.name); set(h_axes(i),'Tag','Cplane'); case 'umat' %%% Umatrix u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'median',... 'mask',sMap.mask(Plane{i}.value)); u=u(:); tmp_h=som_cplane([lattice 'U'],msize,u); set(tmp_h,'EdgeColor','none'); set(h_axes(i),'Tag','Uplane'); h_label(i,1)=xlabel(Plane{i}.name); case 'umati' %%% Umatrix (interpolated shading) u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'mean',... 'mask',sMap.mask(Plane{i}.value)); u=u(1:2:end,1:2:end); u=u(:); tmp_h=som_grid('rect', msize, 'surf', u, ... 'Marker', 'none', 'Line', 'none', ... 'coord', som_vis_coords(lattice,msize)); set(h_axes(i),'Tag','UplaneI'); h_label(i,1)=xlabel(Plane{i}.name); vis_PlaneAxisProperties(gca,lattice,msize,NaN); otherwise error('INTERNAL ERROR: unknown visualization mode.'); end %%% Adjust axis ratios to optimal (only 2D!) and put the %%% title as close to axis as possible set(h_label,'Visible','on','verticalalignment','top'); set(gca,'plotboxaspectratio',[msize(2) msize(1) msize(1)]); %%% Draw colorbars if they are turned on and the plane is umat or c-plane if General.comp(i)> -1 & ~strcmp(General.colorbardir,'none'), h_colorbar(i,1)=colorbar(General.colorbardir); % colorbars else h_colorbar(i,1)=-1; General.comp(i)=-1; endend %% main loop ends % Set window nameset(gcf,'Name',[ 'Map name: ' sMap.name]);%% Set axes handles to the UserData field (for som_addxxx functions%% and som_recolorbar) %% set component indexes and normalization struct for som_recolorbarSOM_SHOW.subplotorder=h_axes;SOM_SHOW.msize=msize;SOM_SHOW.lattice=lattice;SOM_SHOW.dim=d;SOM_SHOW.comps=General.comp;SOM_SHOW.comp_norm=sMap.comp_norm; %(General.comp(find(General.comp>0)));set(gcf,'UserData', SOM_SHOW);% Set text property 'interp' to 'none' in title textsset(h_label,'interpreter','none');h_colorbar=som_recolorbar('all', 3, General.scale); %refresh colorbars% Set a movable text to lower corner pointsize 12.vis_footnote(General.footnote); vis_footnote(12); % set colormapcolormap(General.colormap);%% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if nargout > 0 h.plane=h_axes; h.colorbar=h_colorbar; h.label=h_label;end%%%%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function [Plane, General]=check_varargin(args, munits, dim, name)% args: varargin of the main function% munits: number of map units% dim: map codebook dimension% name: map name% Define some variables (they must exist later)Plane={}; % stores the visualization data for each subplotGeneral.comp=[]; % information stored on SOM_SHOW figure (which component)General.size=[]; % unit sizeGeneral.scale=[]; % normalizationGeneral.colorbardir=[]; % colorbar directionGeneral.edgecolor=[]; % edge colorsGeneral.footnote=name; % footnote textGeneral.colormap=colormap; % default colormap (used to be gray(64).^.5;)General.subplots=[]; % number of subplots in y- and x-directionsfor i=1:2:length(args), %% Check that all argument types are strings if ~ischar(args{i}), error('Invalid input identifier names or input argument order.'); end %% Lower/uppercase in identifier types doesn't matter: identifier=lower(args{i}); % identifier (lowercase) value=args{i+1}; %%% Check first the identifiers that define planes and get values %%% to the visualization data struct array Plane. %%% (comps,compi,umat,color,empty) Note that name, value and comp_ %%% must be specified in these cases %%% comp_ are collected to comp in order. This is stored to the %%% SOM_SHOW user property field to give information for SOM_RECOLROBAR %%% how to operate, i.e., which component is in which subplot: %%% comp(i)=0: draw colorbar, but no normalization (umat) %%% comp(i)=1...N: a component plane of variable comp(i) %%% comp(i)=-1: no colorbar (color or empty plane) switch identifier case {'comp','compi'} %%% Component planes: check values & set defaults if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value), error([ 'A vector argument or string ''all'' expected for ''' ... identifier '''.']) end if isempty(value) value=1:dim; elseif ischar(value), if ~strcmp(value,'all') error([ 'Only string value ''all'' is valid for ''' ... identifier '''.']); else value=1:dim; end else value=round(value); if min(value)<1 | max(value)>dim, error([ 'Component indices out of range in ''' identifier '''.']) end end if size(value,1)==1, value=value';end comp_=value; name=[]; % name is taken form sMap by index in main loop case {'umat','umati'} %%% Check first the possible cell input if iscell(value), if ndims(value) ~= 2 | any(size(value) ~= [1 2]) | ... ~vis_valuetype(value{2},{'string'}), error('Cell input for ''umat'' has to be of form {vector, string}.'); else name=value{2}; value=value{1}; end else name='U-matrix'; % no cell: default title is set end if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value), error('Vector, string ''all'', or cell {vector, string} expected for ''umat''.') end if isempty(value) value=1:dim; elseif ischar(value), if ~strcmp(value,'all') error('Only string value ''all'' is valid for ''umat''.') else value=1:dim; end else value=unique(round(value)); end if min(value)<1 | max(value)>dim, error('Component indices out of range in ''umat''.') end if size(value,1)==1, value=value';end comp_=0; case 'empty' %%% Empty plane: check values & set defaults if ~vis_valuetype(value,{'string'}), error('A string value for title name expected for ''empty''.'); end name=value; comp_=-1; case { 'color','colori'} %%% Color plane: check values & set defaults % Check first the possible cell input if iscell(value), if ndims(value)~=2 | any(size(value) ~= [1 2]) | ... ~vis_valuetype(value{2},{'string'}), error([ 'Cell input for ''' identifier ... ''' has to be of form {M, string}.']); else name=value{2}; value=value{1}; end else name='Color code'; % no cell: default title is set end if size(value,1)~=munits | ... (~vis_valuetype(value,{'nx3rgb'}) & ... ~vis_valuetype(value,{'nx1'}) & ... ~vis_valuetype(value,{'nx1xm'}) & ... ~vis_valuetype(value,{'nx3xdimrgb'})), error(['Mx3 or Mx3xN RGBmatrix, Mx1 or Mx1xN matrix, cell '... '{RGBmatrix, string},' ... ' or {matrix, string} expected for ''' identifier '''.']); end % if colormap is fixed, we don't draw colorbar (comp_ flag is -1) % if colormap is indexed, we draw colorbar as in umat (comp_=0) if size(value,2)==3 comp_=-1; else comp_=0; end %%%% The next things are general properties of the visualization--- %%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% case 'size' %%% Unit size: check & set if ~vis_valuetype(value,{'1x1',[munits 1]}) error('A munits x 1 vector or a scalar expected for ''size''.') end if isempty(value), General.size=1; else General.size=value; end case 'bar' %%% Colorbar existence & direction: check & set if ~vis_valuetype(value,{'string'}) error('String value expected for ''bar''.') elseif isempty(value) value='vert'; end if any(strcmp(value,{'vert','horiz','none'})), General.colorbardir=value; else error('String ''vert'', ''horiz'' or ''none'' expected for ''bar''.'); end case 'norm' %%% Value normalization: check & set if ~vis_valuetype(value,{'string'}) error('String ''n'' or ''d'' expected for ''norm''.'); elseif isempty(value) value='n'; end if strcmp(value(1),'n'), General.scale='normalized'; elseif strcmp(value(1),'d'), General.scale='denormalized'; else error('String ''n(ormalized)'' or ''d(enormalized)'' expected for ''norm''.'); end case 'edge' %%% Edge on or off : check % set if ~vis_valuetype(value,{'string'}) & ~isempty(value), error('String value expected for ''edge''.') elseif ~isempty(value), switch value case 'on' General.edgecolor='k'; case 'off' General.edgecolor='none'; otherwise error('String value ''on'' or ''off'' expected for ''edge''.') end end case 'footnote' %%% Set the movable footnote text if ~vis_valuetype(value,{'string'}) if ~isempty(value), error('String value expected for ''footnote''.'); else General.footnote=sMap.name; end else General.footnote=value; end case 'colormap' %%% Set the colormap if isempty(value) General.colormap=gray(64).^2; elseif ~vis_valuetype(value,{'nx3rgb'}) error('Colormap is invalid!'); else General.colormap=value; end case 'subplots' %%% set the number of subplots if ~vis_valuetype(value,{'1x2'}) & ~vis_valuetype(value,{'2x1'}) error('Subplots grid size is invalid!'); else General.subplots=value; end otherwise %%% Unknown identifier error(['Invalid argument identifier ''' identifier '''!']); end %%% Set new entry to the Plane array if the indentifier means %%% making a new plane/planes tail=length(Plane); switch identifier case {'comp','compi'} for i=1:length(value) Plane{tail+i}.mode=identifier; Plane{tail+i}.value=value(i); Plane{tail+i}.name=name; % not used actually end General.comp = [General.comp; comp_]; case {'umat','umati','empty'} Plane{tail+1}.mode=identifier; Plane{tail+1}.value=value; Plane{tail+1}.name=name; General.comp = [General.comp; comp_]; case {'color','colori'}, for i=1:size(value,3), Plane{tail+i}.mode=identifier; Plane{tail+i}.name=[name '_' num2str(i)]; Plane{tail+i}.value=value(:,:,i); General.comp = [General.comp; comp_]; end if size(value,3)==1, Plane{tail+1}.name=name; end otherwise ; % do nothing endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -