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

📄 modlplts.m

📁 PLS_Toolbox是用于故障检测与诊断方面的matlab工具箱
💻 M
📖 第 1 页 / 共 3 页
字号:
function modlplts(action,fighand)
%MODLPLTS Called by MODLGUI
%
%See instead: MODLGUI

%Copyright Eigenvector Research, Inc. 1997-99
%nbg 4/96,6/97,7/97,12/97,2/98,3/98,5/98,9/98,3/99
%bmw 1/00
%nbg 3/00 (fixed labels for 2d), 11/00 (fixed labels for 3d)

d       = get(fighand,'UserData');
b       = get(d(1,1),'UserData');
e       = get(d(2,1),'UserData');
f       = get(d(3,1),'UserData');
p       = get(0,'DefaultFigurePosition');
e2      = get(e(7,1),'UserData');
f2      = get(get(e(8,1),'UserData'),'UserData');
stat    = get(b(1,1),'UserData');
modl    = get(f(2,1),'UserData');
test    = get(f(5,1),'UserData');
datstat = strcmp(stat.data,'test');
as      = int2str(fighand);
oldqlim = 0;

switch lower(action)
case 'spawn'
  g     = get(gcf,'UserData');
  if isempty(get(get(g(1,1),'userdata'),'ztick'))
    copyobj(get(g(1,1),'UserData'),figure);
  else  
    [az,el] = view;
    copyobj(get(g(1,1),'UserData'),figure);
    view(az,el);
  end
  set(gca,'position',[0.13 0.11 0.775 0.815]);
case 'closescrs'
  h = findobj('Name','Sample Info','Tag',int2str(gcf)); close(h)
  h = findobj('Name','Q Residual Contributions','Tag',int2str(gcf));
  close(h)
  h = findobj('Name','Hotelling T^2 Contributions','Tag',int2str(gcf));
  close(h)
  h = findobj('Name','Plot of Raw Data','Tag',int2str(gcf)); close(h)
  closereq
case 'closelods'
  h = findobj('Name','Variable Info','Tag',int2str(gcf)); close(h)
  h = findobj('Name','Plot of Raw Data','Tag',int2str(gcf)); close(h)
  closereq
case 'plotscores'
  h     = findobj('Name','Plot Scores','Tag',as); close(h)
  h     = figure('Name','Plot Scores','NumberTitle','off', ...
    'Tag',as,'Menu','none','BusyAction','cancel', ...
    'CloseRequestFcn',['modlplts(''closescrs'',',as,')']);
  set(h,'position',[p(1)-35 p(2)-10 380+94 285+46])
  n     = get(f(4,1),'UserData');
  g     = modlpset('plotopts1',h,n);
  s     = ['modlplts(''plotscoresbut'',',as,')'];
  set(g(3,1),'CallBack',s,'TooltipString', ...
    'plot with current settings')
  s     = ['modlplts(''g3on'',',as,')'];
  set(g([4:2:10],1),'Callback',s);
  if datstat
    if isempty(test.slbl)
      s  = str2mat('no label','numbers');
      s2 = 1;
    else
      s  = str2mat('no label','numbers','labels');
      s2 = 3;
    end
    ny   = length(modl.meany);
    s5   = get(g(4,1),'String');
    s1   = str2mat(int2str([1:ny]'));
    s3   = 'y prd  ';
    s3   = [s3(ones(ny,1),:)];
    s3(:,8-size(s1,2):7) = s1;
    s5   = [s5;s3];
    set(g([4 6],1),'String',s5)
    s5 = get(g(8,1),'String');
    s5 = [s5;s3];
    set(g(8,1),'String',s5)
  else
    if isempty(modl.slbl)
      s  = str2mat('no label','numbers');
      s2 = 1;
    else
      s  = str2mat('no label','numbers','labels');
      s2 = 3;
    end
    ny   = length(modl.meany);
    s1   = str2mat(int2str([1:ny]'));
    s3   = 'y prd  ';
    s3   = [s3(ones(ny,1),:)];
    s3(:,8-size(s1,2):7) = s1;
    s3   = ['leverag';s3];
    s4   = 'y mes  ';
    s4   = [s4(ones(ny,1),:)];
    s4(:,8-size(s1,2):7) = s1;
    s3   = [s3;s4];
    s4   = 'y res  ';
    s4   = [s4(ones(ny,1),:)];
    s4(:,8-size(s1,2):7) = s1;    
    s3   = [s3;s4];
    s5   = get(g(4,1),'String');
    set(g([4 6],1),'String',[s5;s3])
    s5    = get(g(8,1),'String');
    set(g(8,1),'String',[s5;s3])
  end
  set(g(10,1),'String',s,'Value',s2)
  set(g(13,1),'Callback', ...
    ['modlplts(''limitchk'',',as,')']);
  set(g(17,1),'String','data','CallBack', ...
    ['modlplts(''scrraw'',',as,')'], ...
    'TooltipString','plot raw data for a sample')
  set(g(18,1),'String','delete','CallBack', ...
    ['modlplts(''scrdel'',',as,')'], ...
    'TooltipString','delete samples')
  if datstat
    set(g(18,1),'Enable','off')
  end
  set(g(19,1),'String','Q con','CallBack', ...
    ['modlplts(''scrqcon'',',as,')'], ...
    'TooltipString','Q residual contribution plot')
  set(g(20,1),'String','T con','CallBack', ...
    ['modlplts(''scrtcon'',',as,')'], ...
    'TooltipString','T^2 contribution plot')
  set(g(21,1),'String','info','CallBack', ...
    ['modlplts(''scrinfo'',',as,')'], ...
    'TooltipString','sample information')
  set(g(22,1),'String','samples')
  set(g(28,1),'String','spawn','CallBack', ...
    ['modlplts(''spawn'',',as,')'], ...
    'TooltipString','create copy of present figure')
  modlplts('plotscoresbut',fighand)
case 'plotloads'
  h     = findobj('Name','Plot Loads','Tag',as); close(h)
  h     = figure('Name','Plot Loads','NumberTitle','off',  ...
    'Tag',as,'Menu','none','BusyAction','cancel', ...
    'CloseRequestFcn',['modlplts(''closelods'',',as,')']);
  set(h,'position',[p(1)-20 p(2)-20 380+94 285+46])
  n     = get(f(4,1),'UserData');
  g     = modlpset('plotopts1',h,n);
  s     = ['modlplts(''plotloadsbut'',',as,')'];
  set(g(3,1),'CallBack',s,'TooltipString', ...
    'plot with current settings')
  s     = 'LV ';
  s     = [s(ones(n,1),:),int2str([1:n]')];
  s2    = 'reg coef ';
  s2    = [s2(ones(size(modl.reg,2),1),:),int2str([1:size(modl.reg,2)]')];
  s1    = str2mat('variable',s,s2);
  set(g(4,1),'String',s1,'Value',1) %set default x for loads
  set(g(6,1),'String',s1,'Value',2) %set default y for loads
  s     = str2mat('none',s,s2);
  set(g(8,1),'String',s,'Value',1)
  s     = ['modlplts(''g3on'',',as,')'];
  set(g([4:2:10],1),'Callback',s);

  s     = str2mat('no label','numbers');
  s2    = 1;
  if (~isempty(modl.vlbl))&(size(modl.vlbl,1)==size(modl.loads,1))
    s   = str2mat('no label','numbers','labels');
    s2  = 3;
  end
  set(g(10,1),'String',s,'Value',s2)
  set(g(12:14,1),'Visible','off')
  set(g(17,1),'String','data','CallBack', ...
    ['modlplts(''lodraw'',',as,')'], ...
    'TooltipString','plot raw data for a variable')
  set(g(18,1),'String','delete','CallBack', ...
    ['modlplts(''loddel'',',as,')'], ...
    'TooltipString','delete variables', ...
    'Visible','off')
  if datstat
    set(g(18,1),'Enable','off')
  end
  set(g(19,1),'String',' ','CallBack', ...
    ['modlplts(''lodqcon'',',as,')'], ...
    'Visible','off')
  set(g(20,1),'String','','CallBack', ...
    ['modlplts(''lodtcon'',',as,')'], ...
    'Visible','off')
  set(g(21,1),'String','info','CallBack', ...
    ['modlplts(''lodinfo'',',as,')'], ...
     'TooltipString','variable information')
  set(g(22,1),'String','variables')
  set(g(28,1),'String','spawn','CallBack', ...
    ['modlplts(''spawn'',',as,')'], ...
    'TooltipString','copy of present figure')
  modlplts('plotloadsbut',fighand)
case 'plotscoresbut'
  if datstat
    if isempty(test.sscl)
      n   = size(test.scores,1);
      sam = [1:n]';
    else
      sam = test.sscl';
    end
    res = test.res;
    tsq = test.tsq;
    scr = test.scores;
    lbl = test.slbl;
    yprd = test.ypred;
  else
    if isempty(modl.sscl)
      sam = modl.irow;
    else
      sam = modl.sscl(modl.irow);
    end
    res = modl.res;
    tsq = modl.tsq;
    scr = modl.scores;
    lbl = modl.slbl;
    yprd = modl.ypred;
  end
  n     = size(scr,2);
  ny    = length(modl.meany);
  g     = get(gcf,'UserData');
  son   = 0;
  pc    = get(g(4,1),'Value');
  if datstat&pc>=n+4
    pc = pc+1;
  end
  if pc==1 %sample
    x   = sam;
    sx  = 'Sample Number';
    son = 1;
  elseif pc==2 %Q
    x   = res;
    sx  = 'Q Residual';
  elseif pc==3 %T
    x   = tsq;
    sx  = 'Hotelling T^2';
  elseif (pc>3)&(pc<n+4) %LVs
    x   = scr(:,pc-3);
    sx  = sprintf('%5.2f',modl.ssq(pc-3,2));
    sx  = [' (',sx,'%)'];
    sx  = ['LV ',int2str(pc-3),sx];
  elseif pc==n+4 %leverage (not avail for test)
    x   = modl.lev;
    sx  = 'Leverage';
  elseif (pc>n+4)&(pc<ny+n+5) %y pred
    x   = yprd(:,pc-n-4);
    sx  = ['Predicted Y(:,',int2str(pc-n-4),')'];
  elseif (pc>ny+n+4)&(pc<2*ny+n+5) %y meas (not avail for test)
    x   = get(f(7,1),'UserData');
    x   = x(modl.irow,pc-ny-n-4);
    sx  = ['Measured Y(:,',int2str(pc-ny-n-4),')'];
  elseif (pc>2*ny+n+4)&(pc<3*ny+n+5) %y res (not avail for test)
    x   = modl.yres(:,pc-2*ny-n-4);
    sx  = ['Studentized Residual for Y(:,',int2str(pc-2*ny-n-4),')'];
  end
  pc    = get(g(6,1),'Value');
  if datstat&pc>=n+4
    pc = pc+1;
  end
  if pc==1 %sample
    y   = sam;
    sy  = 'Sample Number';
    son = 1;
  elseif pc==2 %Q
    y   = res;
    sy  = 'Q Residual';
  elseif pc==3 %T
    y   = tsq;
    sy  = 'Hotelling T^2';
  elseif (pc>3)&(pc<n+4) %LVs
    y   = scr(:,pc-3);
    sy  = sprintf('%5.2f',modl.ssq(pc-3,2));
    sy  = [' (',sy,'%)'];
    sy  = ['LV ',int2str(pc-3),sy];
  elseif pc==n+4 %leverage (not avail for test)
    y   = modl.lev;
    sy  = 'Leverage';
  elseif (pc>n+4)&(pc<ny+n+5) %y pred
    y   = yprd(:,pc-n-4);
    sy  = ['Predicted Y(:,',int2str(pc-n-4),')'];
  elseif (pc>ny+n+4)&(pc<2*ny+n+5) %y meas (not avail for test)
    y   = get(f(7,1),'UserData');
    y   = y(modl.irow,pc-ny-n-4);
    sy  = ['Measured Y(:,',int2str(pc-ny-n-4),')'];
  elseif (pc>2*ny+n+4)&(pc<3*ny+n+5) %y res (not avail for test)
    y   = modl.yres(:,pc-2*ny-n-4);
    sy  = ['Studentized Residual for Y(:,',int2str(pc-2*ny-n-4),')'];
  end
  pc    = get(g(8,1),'Value');
  if datstat&pc>=n+4
    pc = pc+1;
  end
  if pc==1 %none
    z   = [];
  elseif pc==2 %Q
    z   = res;
    sz  = 'Q Residual';
  elseif pc==3 %T
    z   = tsq;
    sz  = 'Hotelling T^2';
  elseif (pc>3)&(pc<n+4) %LVs
    z   = scr(:,pc-3);
    sz  = sprintf('%5.2f',modl.ssq(pc-3,2));
    sz  = [' (',sz,'%)'];
    sz  = ['LV ',int2str(pc-3),sz];
  elseif pc==n+4 %leverage (not avail for test)
    z   = modl.lev;
    sz  = 'Leverage';
  elseif (pc>n+4)&(pc<ny+n+5) %y pred
    z   = yprd(:,pc-n-4);
    sz  = ['Predicted Y(:,',int2str(pc-n-4),')'];
  elseif (pc>ny+n+4)&(pc<2*ny+n+5) %y meas (not avail for test)
    z   = get(f(7,1),'UserData');
    z   = y(modl.irow,pc-ny-n-4);
    sz  = ['Measured Y(:,',int2str(pc-ny-n-4),')'];
  elseif (pc>2*ny+n+4)&(pc<3*ny+n+5) %y res (not avail for test)
    z   = modl.yres(:,pc-2*ny-n-4);
    sz  = ['Studentized Residual for Y(:,',int2str(pc-2*ny-n-4),')'];
  end
  if isempty(z)
    h     = findobj('Tag',['HighOrb',int2str(gcf)]);
    if h
      h   = get(h,'UserData');
      delete(h(:,1));
    end
    set(g(16:size(g,1),1),'Enable','on')
    if datstat
      set(g(18,1),'Enable','off')
    end
    plot(x,y,'or')       %make 2D plot
    if length(sx)>8&length(sy)>8
      if strcmp(sx(1,1:4),'Meas')&strcmp(sy(1,1:4),'Pred')
        if strcmp(sx(1,14),sy(1,15))
          dp
        end
      elseif strcmp(sy(1,1:4),'Meas')&strcmp(sx(1,1:4),'Pred')
        if strcmp(sx(1,15),sy(1,14))
          dp
        end
      end
    end
    if son
      if ishold
        plot(x,y,'-g')
      else
        hold on, plot(x,y,'-g'), hold off
      end
    end

    set(g(20,1),'UserData',h) %set 1st axis for zoom
    
    if get(g(10,1),'Value')==2 %put numbers on
      s   = ' ';
      if datstat
        v = size(scr,1);
        s = [s(ones(v,1)),int2str([1:v]')];
      else
        n = length(modl.irow);
        s = [s(ones(n,1)),int2str((modl.irow)')];
      end
      text(x,y,s,'Fontname','geneva','Fontsize',10);
    elseif (get(g(10,1),'Value')==3)&~isempty(lbl)
      s   = ' ';
      if datstat
        v = size(scr,1);
        s = [s(ones(v,1)),lbl];
      else
        n = length(modl.irow);
        s = [s(ones(n,1)),lbl];
      end
      text(x,y,s,'Fontname','geneva','Fontsize',10);    
    end

    if get(g(13,1),'Value')         %put limit lines on
      modl = get(f(2,1),'UserData');
      lm1 = 0;
      lm2 = 0;
      if isempty(get(f(4,1),'UserData'))
        n = size(modl.scores,2);
      else
        n = get(f(4,1),'UserData'); %PCs kept
      end
      m   = length(modl.irow);      %number of samples
      nx  = length(modl.icol);      %number of x variables
      pc  = get(g(4,1),'Value');    %x axis
      pc2 = get(g(6,1),'Value');    %y axis
      alp = str2num(get(g(12,1),'String'));
      alq = (100-alp)/200;
      h   = axis;

     if pc==1                      % x = sample lm1    
       if pc2==2                   % y = Q lm2
         h(3) = 0;
         if n<nx
		   if isfield(modl,'reseig')
		     lm2 = reslim(0,modl.reseig,alp);
		   else

⌨️ 快捷键说明

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