⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 som_cplane.m

📁 it is matlab code , som(slef organizing map) tool for matlab
💻 M
📖 第 1 页 / 共 2 页
字号:
%%% Check & Init  arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[nargin, lattice, msize, color, s, pos]=vis_planeGetArgs(varargin{:});error(nargchk(3, 5, nargin));  % check no. of input args is correct%% Translation?if nargin < 5 | isempty(pos)  pos=NaN;              % "no translation" flagelseif ~vis_valuetype(pos,{'1x2'}),  error('Position of origin has to be given as an 1x2 vector.');end%% Patchform %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%switch class(lattice)case 'char'             % built-in patchforms  pos=pos-1;  switch lattice  case {'hexa', 'hexaU'}    patchform=vis_patch('hexa');  case {'rect', 'rectU'}    patchform=vis_patch('rect');  otherwise    error([ 'Lattice ' lattice ' not implemented!']);  endcase { 'double', 'sparse'}  if vis_valuetype(lattice,{'nx2'}),    patchform=lattice; % users patchform    lattice='rect';      else    error('Patchform matrix has wrong size');  endotherwise  error('String or matrix expected for lattice.');endl=size(patchform,1);     % number of vertices    planeType=lattice(end);  % 'U' if umatrix otherwise something elseif ~vis_valuetype(msize,{ '1x2', 'nx2'}),  error('msize has to be given as 1x2 or nx2 vectors.');end%% msize or coordinates %%%%%%%%%%%%%%%%%%%%%%%if size(msize,1)>1   % msize is coordinate matrix Nx2?    if planeType == 'U',  % don't accept u-matrix    error('U-matrix visualization doesn''t work with free coordinates.');  end    % set number of map unit and unit coordinates   munits=size(msize,1);  unit_coords=msize; msize=[munits 1];    if isnan(pos),         % no translation is done here     pos=[0 0];           % using [0 0] in order to prevent   end	                 % axis tightening in                         % vis_PlaneAxisProperties (arbitary coords!) else  % msize is built-in lattice    unit_coords=som_vis_coords(lattice,msize);    % Calculate matrices x and y which 'moves' nodes   % to the correct positions:  % For U-matrix, the size has to be recalculated  if planeType == 'U',    xdim=2*msize(1)-1;ydim=2*msize(2)-1;  else    xdim=msize(1);ydim=msize(2);  end  munits=xdim*ydim;    % Feature warning  if munits == 3      warning('Problems with 1x3 and 3x1 maps. See documentation.');  endend%% Color matrix %%%%%%%%%%%%%%%%%%%%%%%%%%%%%if ~isnumeric(color) & ~ischar(color),  error('Color matrix is invalid.');else  d=size(color);             switch length(d)         case 2   %% Flat colors    if ischar(color) % Check for string 'none'      if strcmp(color,'none'), 	color=NaN;      end    else                     if ~(d(1)== 1 & d(2) == 3) & ...	    ~(d(1) == munits & (d(2)==1 | d(2)==3))	error('Color data matrix has wrong size.');      elseif d(1)~=1 & d(2)==3 	if any(color>1 | color<0)	  error('Color data matrix has invalid RGB values.');	end	color=reshape(color,[1 munits 3]);  % RGB colors      elseif d(2)==1	color=color';                       % indexed      end    end  case 3   %% Interpolated colors    if d(1) == 1 & d(2) == munits & d(3) == l,        color=reshape(color, l, munits);    elseif ~(d(1) == l & d(2) == munits & d(3) == 3)       error('Color data matrix has wrong size.');    end  otherwise    error('Color data matrix has too many dimensions.');  endend%% Size matrix? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if nargin < 4 | isempty(s),     s=1;      % default value for s (no scaling)elseif ~isnumeric(s)  error('Size matrix is not numeric.');end%%Determine the type of size matrixd=size(s);                  switch length(d)case 2    if (d(1)==1 & d(2)==1),    % Each node gets the same, uniform scaling.    s=s'; sx=s; sy=s;	  elseif (d(1)==munits & d(2)==l),    % Each vertex is scaled radially respetc to the     % node center.    s=s'; sx=s; sy=s;            elseif d(1)==munits & d(2)==1      % Each node gets an individual uniform scaling.    sx=repmat(s',l,1); sy=sx;  else    error('Size matrix has wrong size.');  endcase 3    if d(1)==munits & d(2)==1 & d(3)==2,         % Each node is individually and uniformly     % scaled separately to x- and y-directions.    sx=repmat(shiftdim(s(:,:,1))',l,1);       sy=repmat(shiftdim(s(:,:,2))',l,1);     elseif d(1)==munits & d(2)==l & d(3)==2,    % Each vertex is scaled separately to x- and y-directions    % with respect to the node center.    sx=shiftdim(s(:,:,1))';                    sy=shiftdim(s(:,:,2))';                else    error('Size matrix has wrong size.');  endotherwise   error('Size matrix has too many dimensions.');end% Size zero would cause division by zero. eps is as good (node disappears)% I tried first NaN, it works well otherwise, but the node is % then not on the axis and some commands may the work oddly. % The edge may be visible, though.sx(sx==0)=eps;                    sy(sy==0)=eps;                % Rescale sizes for u-matrixif planeType=='U',    sx=sx/2;sy=sy/2; end%%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Making grid. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Translation for each patchx=repmat(unit_coords(:,1)',l,1);y=repmat(unit_coords(:,2)',l,1);% patch vertex coordiantes nx=repmat(patchform(:,1),1,munits); ny=repmat(patchform(:,2),1,munits); % NB: The hexagons are not uniform in order to get even  % y-coordinates for the nodes. This is handled by setting _axis scaling_ % so that the hexa-nodes look like uniform hexagonals. See % vis_PlaneAxisProperties%% Make and scale the final input for PATCH:% 1: combine translation and scaling of each patch x=(x./sx+nx).*sx; y=(y./sy+ny).*sy;  %% 2: translation of origin (pos)if ~isnan(pos)   x=x+pos(1);y=y+pos(2);    % move upper left corner end                         % to pos%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Set axes properties  %% Command view([0 90]) shows the map in 2D properly orientedax=newplot;                               % set new plotvis_PlaneAxisProperties(ax,lattice,msize,pos);%% Draw the map! if ~isnan(color)   h_=patch(x,y,color);         else   h_=patch(x,y,'k');                     % empty grid    set(h_,'FaceColor','none');end%% Set object tagif planeType=='U'   set(h_,'Tag','planeU');                      else   set(h_,'Tag','planeC');end	%%% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if nargout>0, h=h_; end                   % Set h only,                                           % if there really is output

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -