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

📄 modlgui.m

📁 PLS_Toolbox是用于故障检测与诊断方面的matlab工具箱
💻 M
📖 第 1 页 / 共 4 页
字号:
      stat.modl  = 'calnew';
    else
      stat.modl  = 'none';
    end
  case 'splits'
    s        = round(get(e2(2,1),'value'));
    set(e2(2,1),'Value',s), set(f2(2,1),'String',int2str(s))
    modl.split   = s;
    stat.modl    = 'none';
  case 'iterations'
    s        = round(get(e2(3,1),'value'));
    set(e2(3,1),'Value',s), set(f2(3,1),'String',int2str(s))
    modl.iter    = s;
    stat.modl    = 'none';
  case 'scaling'
    switch get(e2(4,1),'value')
    case 1
      modl.scale = 'none';
    case 2
      modl.scale = 'mean';
    case 3
      modl.scale = 'auto';
    end
    stat.modl    = 'none';
  case 'regression'
    switch get(e2(5,1),'value')
    case 1
      modl.name  = 'nip';
    case 2
      modl.name  = 'sim';
    case 3
      modl.name  = 'pcr';
    end
    stat.modl    = 'none';
  case 'crossval'
    switch get(e2(6,1),'value')
    case 1
      modl.cv    = 'loo';
    case 2
      modl.cv    = 'vet';
    case 3
      modl.cv    = 'con';
    case 4
      modl.cv    = 'rnd';
    end
    stat.modl    = 'none';
  end

  %button/slider/popup status
  if ~strcmp(lower(action),'exitmodl')
    set(b(1,1),'UserData',stat)
    set(f(2,1),'UserData',modl)
    set(f(5,1),'UserData',test)
    if strcmp(stat.data,'none')
      %no data, w/ and w/o model
      set(f(1:7,1),'Enable','off')
      set(e2(1:6,1),'Enable','off')
    elseif ~strcmp(stat.data,'none')&strcmp(stat.modl,'none')
      %new data, no model
      set(f([1 7],1),'Enable','on')
      set(f(2:6,1),'Enable','off')
      set(e2([1:6],1),'Enable','on')
    elseif ~strcmp(stat.data,'none')&(~strcmp(stat.modl,'none'))
      %data and model
      if strcmp(stat.modl,'calold')
        set(f(1:2,1),'Enable','off')
        set(f(3:7,1),'Enable','on')
        set(e2(1:6,1),'Enable','on')
      elseif strcmp(stat.modl,'calnew')
        set(f([1 4:6],1),'Enable','off')
        set(f([2:3 7],1),'Enable','on')
        set(e2(1:6,1),'Enable','on')
      elseif strcmp(stat.modl,'loaded')
        set(e2(1:6,1),'Enable','off')
        if strcmp(stat.data,'test')
          set(f(1:2,1),'Enable','off')
          set(f(3:7,1),'Enable','on')
        else
          set(f([1 3:6],1),'Enable','off')
          set(f([2 7],1),'Enable','on')
        end
      end
    end
    if strcmp(get(e2(1,1),'Enable'),'on')
      switch get(e2(6,1),'value')
      case 1
        modl.cv    = 'loo';
        set(e2(2:3,1),'Enable','off')
        set(e2([2:3 9:12],1),'Visible','off') %iterations/splits
        set(f2([2 3 5 6],1),'Visible','off')
      case 2
        modl.cv    = 'vet';
        set(e2(3,1),'Enable','off')
        set(e2(2,1),'Enable','on')
        set(e2([3 11 12],1),'Visible','off')  %iterations
        set(f2([3 6],1),'Visible','off')
        set(e2([2 9 10],1),'Visible','on')    %splits
        set(f2([2 5],1),'Visible','on')
      case 3
        modl.cv    = 'con';
        set(e2(3,1),'Enable','off')
        set(e2(2,1),'Enable','on')
        set(e2([3 11 12],1),'Visible','off')  %iterations
        set(f2([3 6],1),'Visible','off')
        set(e2([2 9 10],1),'Visible','on')    %splits
        set(f2([2 5],1),'Visible','on')
      case 4
        modl.cv    = 'rnd';
        set(e2(2:3,1),'Enable','on')
        set(e2([2:3 9:12],1),'Visible','on') %iterations/splits
        set(f2([2 3 5 6],1),'Visible','on')
      end
    end
    if ~strcmp(stat.data,'none')
      if ~isempty(modl.drow)
        modl.irow      = delsamps([1:size(get(f(1,1),'UserData'),1)]',modl.drow);
      end
      s = min([length(modl.irow) length(modl.icol) 40 rank(get(f(1,1),'UserData'))]');
      set(f2(4,1),'String',int2str(s))
      if get(e2(1,1),'Value')>s
        set(e2(1,1),'Value',s)
        set(f2(1,1),'String',int2str(s))
      end
      set(e2(1,1),'Max',s)
    end
    if get(f(4,1),'UserData')<2
      set(f(6,1),'Enable','off') %biplot button
      h = findobj('Name','Biplot ','Tag',as); close(h)
    end
    %status strings and file menu
    if strcmp(stat.modl,'none')
      set(f(3:4,1),'UserData',[])
      set(e(3,1),'String',' ')
      set(e(4,1),'String',' ','Value',1)
      if strcmp(stat.data,'none')
        s  = ['Model: none loaded'];
      else
        s  = ['Model: not calculated'];
      end
      set(e(6,1),'String',s)
      set(bb([8 10 14],1),'Enable','off');
    else
      set(bb([8 10 14],1),'Enable','on');
      switch stat.modl  
      case 'loaded'
        if strcmp(stat.data,'none')
          s  = ['Model: loaded'];
          set(bb(1,1),'Enable','on')  %load data
        elseif strcmp(stat.data,'new')
          s  = ['Model: loaded but not applied'];
          set(bb(1,1),'Enable','off')  %load data
        elseif strcmp(stat.data,'test')
          s  = ['Model: loaded and applied'];
          set(bb(1,1),'Enable','off')  %load data
        end
      case 'calnew'
        s  = ['Model: not applied'];
        set(bb([1 12],1),'Enable','off')
      case 'calold'
        s  = ['Model: calibrated on loaded data'];
          set(bb(1,1),'Enable','off')  %load data
      end
      modl = get(f(2,1),'UserData');
      pc   = size(modl.loads,2);
      if strcmp(modl.scale,'auto')
        sc = 'autoscaled';
      elseif strcmp(modl.scale,'mean')
        sc = 'mean centered';
      else
        sc = 'not scaled';
      end
      switch lower(modl.name)
      case 'nip'
        s0 = 'NIPLS';
      case 'sim'
        s0 = 'SIMPLS';
      case 'pcr'
        s0 = 'PCR';
      end
      s0   = ['Method: ',s0];
      s1   = ['LV(s): ',int2str(pc)];
      s2   = ['Scaling: ',sc];
      s3   = ['Data: ',int2str(length(modl.irow)),' by ', ...
        int2str(length(modl.icol)),', ', ...
        int2str(length(modl.irow)),' by ', ...
        int2str(length(modl.meany))];
      set(e(6,1),'String',str2mat(s,s0,s1,s3,s2))
    end
    if strcmp(stat.data,'none')
      set(f(1,1),'UserData',[])
      set(e(5,1),'String','Data: none loaded')
      set(b(2:3,1),'Enable','off');
      set(bb([3:7 9],1),'Enable','off');
    else
      set(b(2:3,1),'Enable','on')
      set(bb([3:6 9],1),'Enable','on')
      if modl.drow|modl.dcol
        set(bb(7,1),'Enable','on');
      end
      if ~strcmp(stat.modl,'loaded')
        set(bb([4 6],1),'Enable','on');
      else
        set(bb([4 6],1),'Enable','off');
      end
      if strcmp(stat.data,'new')
        s   = ['Data: loaded but not analyzed'];
        s4  = ['Samp Lbls: ',modl.slbln];
      elseif strcmp(stat.data,'cal')
        s   = ['Data: modeled (calibration set)'];
        s4  = ['Samp Lbls: ',modl.slbln];
      elseif strcmp(stat.data,'test')
        s   = ['Data: modeled (test set)'];
        s4  = ['Samp Lbls: ',test.slbln];
      end
      [m,n] = size(get(f(1,1),'UserData'));
      if ~strcmp(stat.data,'cal')
        s3    = ['Var: ',get(d(4,1),'UserData'),', ',get(f(6,1),'UserData')];
        s2    = ['Size: ',int2str(m),' by ',int2str(n),', ',int2str(m), ...
          ' by ',int2str(size(y,2))];
      else
        s3    = ['Var: ',get(d(4,1),'UserData'),',', ...
          get(f(6,1),'UserData')];
        s2    = ['Size: ',int2str(m),' by ',int2str(n), ...
          ', ',int2str(m),' by ', ...
          int2str(size(get(f(7,1),'UserData'),2))];
      end
      s5    = ['Var Lbls: ',modl.vlbln];
      set(e(5,1),'String',str2mat(s3,s,s2,s4,s5))
    end
  end
end

function delfigs(as)
h = findobj('Name','PRESS','Tag',as);       close(h)
h = findobj('Name','Plot Scores','Tag',as); close(h)
h = findobj('Name','Plot Loads','Tag',as);  close(h)
h = findobj('Name','Biplot','Tag',as);      close(h)
h = findobj('Name','Data Plot','Tag',as);   close(h)

function [p,e,f] = regset(a)
bgc0    = [0 0 0];
bgc1    = [1 0 1]*0.6;
bgc2    = [1 1 1]*0.85;
bgc3    = [1 1 1];
fsiz    = 12;
fnam    = 'geneva';
as      = int2str(a);
p       = get(a,'Position');
p       = figure('Color',bgc0,'Resize','on', ...
  'Name','Regression Parameters','Tag',as, ...
  'NumberTitle','Off','Position',[p(1)+200 p(2)-20 380 239], ...
  'HandleVisibility','off', ...
  'CloseRequestFcn',['modlgui(''showp2'',',as,');']);
e       = zeros(15,1);
%Frames
d(1,1)  = uicontrol('Parent',p,'Style','frame', ...
  'Position',[11 11 144 225]);
d(2,1)  = uicontrol('Parent',p,'Style','frame', ...
  'Position',[157 11 214 225]);
d(3,1)  = uicontrol('Parent',p,'Style','frame', ...
  'Position',[14 14 138 219]);
d(4,1)  = uicontrol('Parent',p,'Style','frame', ...
  'Position',[160 14 208 219]);
%Max LV slider
e(1,1)  = uicontrol('Parent',p,'Style','slider', ...
  'Position',[194 180 140 18],'Min',1,'Max',2,'Value',1, ...
  'CallBack',['modlgui(''maxlvs'',',as,');'], ...
  'SliderStep',[0.03 0.06]);
e(7,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[194 160 110 18], ...
  'String','Max LVs','HorizontalAlignment','left');
e(8,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[164 180 30 20], ...
  'String',num2str(get(e(1,1),'Min')));
f(4,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[334 180 30 20], ...
  'String',num2str(get(e(1,1),'Max')));
f(1,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[304 160 30 20], ...
  'String',num2str(get(e(1,1),'Value')));
%Splits slider
e(2,1)  = uicontrol('Parent',p,'Style','slider', ...
  'Position',[194 130 140 18],'Min',2,'Max',20,'Value',2, ...
  'CallBack',['modlgui(''splits'',',as,');'], ...
  'SliderStep',[0.05 0.1]);
e(9,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[194 110 110 18], ...
  'String','# Splits','HorizontalAlignment','left');
e(10,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[164 130 30 20], ...
  'String',num2str(get(e(2,1),'Min')));
f(5,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[334 130 30 20], ...
  'String',num2str(get(e(2,1),'Max')));
f(2,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[304 110 30 20], ...
  'String',num2str(get(e(2,1),'Value')));
%Iterations slider
e(3,1)  = uicontrol('Parent',p,'Style','slider', ...
  'Position',[194 80 140 18],'Min',1,'Max',30,'Value',5, ...
  'CallBack',['modlgui(''iterations'',',as,');'], ...
  'SliderStep',[0.034 0.08]);
e(11,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[194 60 110 18], ...
  'String','# Iterations','HorizontalAlignment','left');
e(12,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[164 80 30 20], ...
  'String',num2str(get(e(3,1),'Min')));
f(6,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[334 80 30 20], ...
  'String',num2str(get(e(3,1),'Max')));
f(3,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[304 60 30 20], ...
  'String',num2str(get(e(3,1),'Value')));
%Scaling Popup
s       = str2mat('none','mean center','autoscale');
e(4,1)  = uicontrol('Parent',p,'Style','popupmenu', ...
  'Position',[24 180 118 18],'String',s,'Value',3, ...
  'CallBack',['modlgui(''scaling'',',as,');']);
e(13,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[24 160 118 18],'String','Scaling', ...
  'HorizontalAlignment','left');
%Regression Popup
s       = str2mat('NIPLS','SIMPLS','PCR');
e(5,1)  = uicontrol('Parent',p,'Style','popupmenu', ...
  'Position',[24 130 118 18],'String',s,'Value',2, ...
  'CallBack',['modlgui(''regression'',',as,');']);
e(14,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[24 110 118 18],'String','Regression', ...
  'HorizontalAlignment','left');
%Cross Validation Popup
s       = str2mat('leave one out','venetian blinds', ...
  'contiguous block','random subsets');
e(6,1)  = uicontrol('Parent',p,'Style','popupmenu', ...
  'Position',[24 80 118 18],'String',s,'Value',2, ...
  'CallBack',['modlgui(''crossval'',',as,');']);
e(15,1)  = uicontrol('Parent',p,'Style','text', ...
  'Position',[24 60-18 118 36],'String','Cross Validation', ...
  'HorizontalAlignment','left');
%set common properties
set(d(1:2,1),'BackgroundColor',bgc1,'Units','normalized')
set(d(3:4,1),'BackgroundColor',bgc3,'Units','normalized')
set(e(1:6,1),'BackgroundColor',bgc2,'Units','normalized', ...
  'Enable','off')
set(e(4:6,1),'FontName',fnam,'FontSize',fsiz-1)
set(e(7:15,1),'BackgroundColor',bgc3,'Units','normalized', ...
  'FontName',fnam,'FontSize',fsiz,'FontWeight','bold')
set(f(1:6,1),'BackgroundColor',bgc3,'Units','normalized', ...
  'FontName',fnam,'FontSize',fsiz,'FontWeight','bold')

⌨️ 快捷键说明

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