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

📄 som_select.m

📁 此源码提供了ssvm的完整的matlab源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout=som_select(c_vect,plane_h,arg)%SOM_SELECT  Manual selection of map units from a visualization.%% som_select(c_vect,[plane_h])%     %   som_select(3)%   som_select(sM.labels(:,1))%%  Input arguments ([]'s are optional):%   c_vect    (scalar) number of classes %             (vector) initial class identifiers%             (cell array) of strings, class names%             (matrix) size * x 3, the color of each class%   [plane_h] (scalar) handle of the plane (axes) to be marked. %                      By default, the current axes is used (GCA).%                      For the function to work, the plot in the %                      axes must have been created with the%                      SOM_CPLANE function (or SOM_SHOW).% % Launches a GUI which allows user to select nodes from plane by % clicking them or by choosing a region (a polygon). % %   Middle mouse button: selects (or clears selection of) a single node%   Left mouse button:   lets user draw a polygon%   Right mouse button:  selects (or clears selection of) the units %                        inside the polygon% % From the GUI, the color (class) is selected as well as whether% but buttons select or clear the selection from the units. The% buttons on the bottom have the following actions: % %   'OK'    Assigns the class identifiers to the 'ans' variable in %           workspace. The value is an array of class identifiers: %           strings (cellstr) if the c_vect was an array of%           strings, a vector otherwise.%   'Clear' Removes marks from the plane.%   'Close' Closes the application. %% See also SOM_SHOW, SOM_CPLANE.% Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas % Copyright (c) by Juha Parhankangas% http://www.cis.hut.fi/projects/somtoolbox/% Juha Parhankangas 050100, juuso 010200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% input argumentsif nargin < 2, plane_h = gca; endif(isempty(gcbo)), arg='start'; end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% actionswitch arg case 'start'  patch_h=find_patch(plane_h);  lattice=getfield(size(get(patch_h,'XData')),{1});  msize(1)=floor(getfield(get(plane_h,'YLim'),{2}));   msize(2)=floor(getfield(get(plane_h,'XLim'),{2})-0.5);     if lattice==6    lattice='hexa';  else    lattice='rect';  end    if any(strcmp(get(patch_h,'Tag'),{'planeBar','planePie'}))    tmp_dim=size(get(patch_h,'XData'),2)/prod(msize);    tmp_xdata=get(patch_h,'XData');    tmp_x=tmp_xdata(:,(msize(1)*(msize(2)-1)+2)*tmp_dim);    if floor(tmp_x(1)) ~= round(tmp_x(1))      lattice = 'hexa';    else      lattice = 'rect';    end  elseif strcmp(get(patch_h,'Tag'),'planePlot')    tmp_lines_h=get(gca,'Children');    test_x=mean(get(tmp_lines_h(2),'XData'));    if round(test_x) ~= floor(test_x)      lattice = 'hexa';    else      lattice = 'rect';    end    form=0.5*vis_patch('hexa');    l = size(form,1);        nx = repmat(form(:,1),1,prod(msize));    ny = repmat(form(:,2),1,prod(msize));        x=reshape(repmat(1:msize(2),l*msize(1),1),l,prod(msize));    y=repmat(repmat(1:msize(1),l,1),1,msize(2));        if strcmp(lattice,'hexa')      t = find(~rem(y(1,:),2));      x(:,t)=x(:,t)+.5;    end    x=x+nx;    y=y+ny;        colors=reshape(ones(prod(msize),1)*[NaN NaN NaN],...		   [1 prod(msize) 3]);    v=caxis;    patch_h=patch(x,y,colors,...		  'EdgeColor','none',...		  'ButtonDownFcn',...		  'som_select([],[],''click'')',...		  'Tag','planePlot');    set([gca gcf],'ButtonDownFcn','som_select([],[],''click'')');    caxis(v)  end  c_colors = [];   if iscell(c_vect)    [c_vect,c_names,c_classes]=class2num(c_vect);    if length(c_classes)<prod(msize),       c_classes = zeros(prod(msize),1);    end  else    if all(size(c_vect)>1),       c_colors = c_vect;       c_names = 1:size(c_vect,1);       c_vect = size(c_vect,1);       c_classes = zeros(prod(msize),1);    elseif length(c_vect)==prod(msize),      c_classes = c_vect;      u = unique(c_classes(isfinite(c_classes) & c_classes>0));      c_names = u;      c_vect = length(u);           elseif length(c_vect)>1,       c_names = c_vect;       c_vect = length(c_vect);      c_classes = zeros(prod(msize),1);    elseif length(c_vect)==1,      c_names = 1:c_vect;              c_classes = zeros(prod(msize),1);    end  end    udata.lattice=lattice;  udata.patch_h=patch_h;  udata.plane_h=plane_h;  udata.type=get(udata.patch_h,'Tag');  udata.msize=msize;  set(patch_h,'UserData',udata);  if strcmp(udata.type,'planePlot')    set([gca gcf],'UserData',udata);  end  str=cat(2,'som_select([],[],''click'')');  set(patch_h,'ButtonDownFcn',str);  draw_colorselection(c_names,c_colors);  tmp_data=findobj(get(0,'Children'),'Tag','SELECT_GUI');  tmp_data=get(tmp_data,'UserData');  tmp_data.c_names=c_names;  tmp_data.mat=reshape(c_classes,msize);  tmp_data.patch_h=patch_h;  tmp_data.plane_h=plane_h;  tmp_data.type=get(udata.patch_h,'Tag');  tmp_data.lattice=lattice;  tmp_data.coords=[];  tmp_data.poly_h=[];  tmp_data.msize=msize;  tmp_data.mode='select';    set(tmp_data.fig_h,'UserData',tmp_data);     draw_classes;   case 'click'  switch get(gcf,'SelectionType')   case 'open'    return;   case {'normal','alt'}    draw_poly;   case 'extend'    click;  end  case 'choose'  draw_colorselection(0,0,'choose'); case 'close'  close_gui; case 'clear'  clear_plane; case 'rb'  rb_control; case 'ret_mat'  gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');  gui=get(gui,'UserData');  mat=reshape(gui.mat,prod(size(gui.mat)),1);  if ~isempty(gui.c_names)    if isnumeric(gui.c_names), tmp=zeros(length(mat),1);    else tmp=cell(length(mat),1);    end    for i=1:length(gui.c_names)      inds=find(mat==i);      tmp(inds)=gui.c_names(i);    end           mat=tmp;  end    varargout{1}=mat;  %gui.mat=zeros(size(gui.mat));  %set(gui.fig_h,'UserData',gui);  %h=findobj(get(gui.plane_h,'Children'),'Tag','SEL_PATCH');  %delete(h);end  return;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subfunctionsfunction rb_control;h=findobj(get(gcf,'Children'),'Style','radiobutton');set(h,'Value',0);set(gcbo,'Value',1);udata=get(gcf,'UserData');if strcmp(get(gcbo,'Tag'),'Radiobutton1')  udata.mode='select';else  udata.mode='clear';endset(gcf,'UserData',udata);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function clear_planeh=findobj(get(0,'Children'),'Tag','SELECT_GUI');gui=get(h,'UserData');if strcmp(get(gui.patch_h,'Tag'),'planePlot')  colors=reshape(get(gui.patch_h,'FaceVertexCData'),[prod(gui.msize) 3]);  colors(:,:)=NaN;  set(gui.patch_h,'FaceVertexCData',colors);endh=findobj(get(gui.plane_h,'Children'),'Tag','SEL_PATCH');gui.mat=zeros(gui.msize);set(gui.fig_h,'UserData',gui);delete(h);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function clickudata=get(gcbo,'UserData');udata=get(udata.patch_h,'UserData');  coords=get(gca,'CurrentPoint');row=round(coords(1,2));if row > udata.msize(1), row = udata.msize(1); endif row < 1, row = 1; endif any(strcmp(udata.lattice,{'hexa','hexaU'})) & ~mod(row,2),   col=floor(coords(1,1))+0.5;  if col > udata.msize(2)+0.5, col=udata.msize(2)+0.5; endelse  col=round(coords(1,1));  if col > udata.msize(2), col=udata.msize(2); endendif col < 1, col = 1; endif strcmp(udata.type,'planePlot')  if ~mod(row,2) & strcmp(udata.lattice,'hexa'), col=round(col-0.5); end    ind=sub2ind(udata.msize,row,col);  colors=reshape(get(udata.patch_h,'FaceVertexCData'),[prod(udata.msize) 3]);  gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');  gui=get(gui,'UserData');    if ~isempty(gui.curr_col) & all(~isnan(colors(ind,1,:))),    if ~strcmp(gui.mode,'clear') & ~all(gui.curr_col == colors(ind,:))      colors(ind,:)=gui.curr_col;      gui.mat(row,col)=gui.class;    else      colors(ind,:)=[NaN NaN NaN];      gui.mat(row,col)=0;    end  elseif strcmp(gui.mode,'clear')    colors(ind,:)=[NaN NaN NaN];    gui.mat(row,col)=0;  elseif isempty(gui.curr_col)    return;  else    gui.mat(row,col)=gui.class;    colors(ind,:)=gui.curr_col;  end  set(udata.patch_h,'FaceVertexCData',colors);  set(gui.fig_h,'UserData',gui);  return;end  if any(strcmp(udata.type,{'planePie','planeBar'}))  [x,y]=pol2cart(0:0.1:2*pi,0.5);  coords=[x';0.5]*0.7;  coords(:,2)=[y';0]*0.7;elseif strcmp(udata.lattice,'hexa');  coords=0.7*vis_patch('hexa');else  coords=0.7*vis_patch('rect');endcoords(:,1)=coords(:,1)+col;coords(:,2)=coords(:,2)+row;if ~mod(row,2) & strcmp(udata.lattice,'hexa'), col=round(col-0.5); end hold on;if gco == udata.patch_h  gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');  gui=get(gui,'UserData');  if isnan(gui.curr_col) | strcmp(gui.mode,'clear'), return; end  h=fill(coords(:,1),coords(:,2),gui.curr_col);  str=cat(2,'som_select([],[],''click'')');  set(h,'ButtonDownFcn',str,'Tag','SEL_PATCH');  tmp.patch_h=udata.patch_h;  set(h,'UserData',tmp);  gui.mat(row,col)=gui.class;  set(gui.fig_h,'UserData',gui);else  gui=findobj(get(0,'Children'),'Tag','SELECT_GUI');  gui=get(gui,'UserData');  if ~all(get(gcbo,'FaceColor') == gui.curr_col) & ~strcmp(gui.mode,'clear'),    if ~isnan(gui.curr_col),       set(gcbo,'FaceColor',gui.curr_col);      gui.mat(row,col) = gui.class;    end  else    gui.mat(row,col)=0;    delete(gco);  end  set(gui.fig_h,'UserData',gui);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function draw_colorselection(varargin)if length(varargin)==2,   if length(varargin{1})==1,     n = varargin{1};    names = 1:n;  else    n = length(varargin{1});     names = varargin{1};   end  colors = varargin{2};     shape=[0.5 -0.5;0.5 0.5;1.5 0.5;1.5 -0.5];  rep_x=repmat(shape(:,1),1,n);  rep_y=repmat(shape(:,2),1,n);  for i=0:getfield(size(rep_y,2))-1, rep_x(:,i+1)=rep_x(:,i+1)+i; end  if isempty(colors), colors=jet(n); end  data=som_select_gui;  data.colors=colors;  data.curr_col=NaN;  data.class=0;

⌨️ 快捷键说明

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