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

📄 gcluster.m

📁 偏最小二乘算法在MATLAB中的实现
💻 M
字号:
function gcluster(dat,labels,action);
%GUI for cluster function.
%
%I/O format is: gcluster(dat,labels);

if nargin<3
   action = 'initiate';
   if nargin<2
      labels = [];
   end
   if nargin<1
      dat = [];
   end
end

if strcmp(action,'initiate')
  handl   = zeros(8,8);
  bgc        = 'BackGroundColor';
  bgc1       = [0.8 0.8 0.8];
  bgc2       = [1 0 0];

  fig00      = figure('Name','Cluster Analysis with Dendrograms',...
               'Pos',[11 19 480 320],'Resize','Off','NumberTitle','Off');               
  
  frame1     = uicontrol(fig00,'Style','Frame',bgc,bgc2,'Pos',[11 131 220 110]);
  handl(2,1) = uicontrol(fig00,'Style','Text','Pos',[15 135 212 102],...
               'String','Clustering Algorithm','UserData',dat,bgc,[1 1 1]);       
  handl(3,1) = uicontrol(fig00,'Style','Radio','Pos',[50 197 150 20],...
 			   'String',' k nearest neighbor',bgc,[1 1 1],'Value',1,...
               'Userdata',labels,'CallBack','gcluster(0,0,''act31'')');
  handl(4,1) = uicontrol(fig00,'style','radio','Pos',[50 167 150 20],...
 			   'string',' k means',bgc,[1 1 1],'value',0,...
               'callback','gcluster(0,0,''act41'')');		  

  frame2     = uicontrol(fig00,'Style','Frame','Pos',[11 11 220 110],...
               bgc,bgc2);
  handl(1,2) = 1;
  handl(2,2) = uicontrol(fig00,'Style','Text','Pos',[15 15 212 102],...
               bgc,[1 1 1],'String','Scaling');	   
  handl(3,2) = uicontrol(fig00,'Style','Radio','Pos',[50 17 150 20],...
               'Value',0,bgc,[1 1 1],'String',' none',...
               'CallBack','gcluster(0,0,''act32'')',...
               'Visible','Off');
  handl(4,2) = uicontrol(fig00,'Style','Radio','Pos',[50 77 150 20],...
               'Value',0,bgc,[1 1 1],'String',' mean center',...
               'CallBack','gcluster(0,0,''act42'')');
  handl(5,2) = uicontrol(fig00,'Style','Radio','Pos',[50 47 150 20],...
               'Value',1,bgc,[1 1 1],'String',' Autoscale',...
               'Callback','gcluster(0,0,''act52'')');

  frame3     = uicontrol(fig00,'Style','Frame','Pos',[11 251 460 60],bgc,bgc2);
  handl(2,3) = uicontrol(fig00,'style','text','Pos',[15 255 452 52],...
               bgc,[1 1 1],'String','Cluster Analysis with Dendrograms');

  frame4     = uicontrol(fig00,'Style','Frame','Pos',[251 156 220 85],bgc,bgc2);
  handl(1,4) = 0;
  handl(2,4) = uicontrol(fig00,'Style','Text','Pos',[255 160 212 77],...
               bgc,[1 1 1],'string','Use PCA?');	   
  handl(3,4) = uicontrol(fig00,'Style','Radio','Pos',[290 197 150 20],...
               'Value',1,bgc,[1 1 1],'String',' no',...
               'CallBack','gcluster(0,0,''act34'')');
  handl(4,4) = uicontrol(fig00,'Style','Radio','Pos',[290 167 150 20],...
               'Value',0,bgc,[1 1 1],'String',' yes',...
               'CallBack','gcluster(0,0,''act44'')');

  handl(1,8) = 0;
  handl(2,8) = uicontrol(fig00,'Style','Frame','Pos',[251 61 220 85],...
               bgc,bgc2,'Visible','Off');
  handl(3,8) = uicontrol(fig00,'Style','Text','Pos',[255 65 212 77],bgc,[1 1 1],...
               'String','Use Mahalanobis Distance Measure?','Visible','Off');
  handl(4,8) = uicontrol(fig00,'Style','Radio','Pos',[290 102 150 20],...
               'Value',1,bgc,[1 1 1],'String',' no',...
               'CallBack','gcluster(0,0,''act48'')','Visible','Off');
  handl(5,8) = uicontrol(fig00,'Style','Radio','Pos',[290 72 150 20],...
               'Value',0,bgc,[1 1 1],'String',' yes',...
               'CallBack','gcluster(0,0,''act58'')','Visible','Off');

  handl(2,5) = uicontrol(fig00,'Style','Push','Pos',[366 11 105 37],...
               'String','Quit','Callback','gcluster(0,0,''act25'')',...
			   bgc,bgc1);
  handl(2,7) = uicontrol(fig00,'Style','Push','Pos',[251 11 105 37],...
               'String','Execute','CallBack','gcluster(0,0,''act27'')',...
			   bgc,bgc1);

  set(fig00,'userdata',[handl]);
else
  fig00      = gcf;
  handl      = get(fig00,'userdata');
  bgc        = 'BackGroundColor';

  if strcmp(action,'act27')
	dat      = get(handl(2,1),'userdata');
    labels   = get(handl(3,1),'userdata');
    if isempty(dat)
	  handl(1,1) = 0;
	  set(handl(2,3),'string','ERROR - input data not found -')	
   	else
	  set(handl(2,3),'string','executing',bgc,[1 1 1]);
      handl(1,1) = figure('color',[0 0 0],'Pos',[201 190 480 320],...
                   'Name','Dendrogram','NumberTitle','Off','Resize','On');
	  set(fig00,'UserData',handl);
	  cluster(dat,labels,fig00);
    end
  elseif strcmp(action,'act31')
    set(handl(3,1),'value',1);
    set(handl(4,1),'value',0);
    set(handl(2,3),'string',' ',bgc,[1 1 1]);
  elseif strcmp(action,'act41')
    set(handl(3,1),'value',0);
    set(handl(4,1),'value',1);
    set(handl(2,3),'string',' ',bgc,[1 1 1]);
  elseif strcmp(action,'act32')
    set(handl(3,2),'value',1);
    set(handl(4:5,2),'value',0);
	handl(1,2)  = 0;
    set(handl(2,3),'string',' ',bgc,[1 1 1]);
  elseif strcmp(action,'act42')
    set(handl(3:5,2),'value',0);
    set(handl(4,2),'value',1);
	handl(1,2)  = 2;
    set(handl(2,3),'string',' ',bgc,[1 1 1]);
  elseif strcmp(action,'act52')
    set(handl(3:5,2),'value',0);
   	set(handl(5,2),'value',1);
   	handl(1,2)  = 1;
    set(handl(2,3),'string',' ',bgc,[1 1 1]);
  elseif strcmp(action,'act34')
    set(handl(3,4),'value',1);
    set(handl(4,4),'value',0);
   	set(handl(2:5,8),'visible','off');
    set(handl(2,3),'string',' ',bgc,[1 1 1]);
   	handl(1,4)  = 0;
    set(handl(4,8),'value',1);
    set(handl(5,8),'value',0);
    handl(1,8)  = 0;
  elseif strcmp(action,'act44')
    set(handl(3,4),'value',0);
    set(handl(4,4),'value',1);
   	set(handl(2:5,8),'visible','on');
   	set(handl(2,3),'string',['on execution the PCA routine will',...
        ' a)  list the PC variance statistics, and',...
        ' b)  prompt you for the appropriate number of PCs to use',...
        ' in the COMMAND WINDOW']);
   	handl(1,4)  = 1;
    set(handl(4,8),'value',1);
    set(handl(5,8),'value',0);
    handl(1,8)  = 0;
  elseif strcmp(action,'act48')
    set(handl(4,8),'value',1);
    set(handl(5,8),'value',0);
    handl(1,8)  = 0;
  elseif strcmp(action,'act58')
    set(handl(4,8),'value',0);
    set(handl(5,8),'value',1);
    handl(1,8)  = 1;
  end
	
  set(fig00,'userdata',[handl]);
  
  if strcmp(action,'act25')
    close;
  end
end

⌨️ 快捷键说明

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