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

📄 pcaplots.m

📁 PLS_Toolbox是用于故障检测与诊断方面的matlab工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
    if strcmp(modl.name,'PCA')
      sy  = sprintf('%5.2f',modl.ssq(pc-1,3));
      sy  = [' (',sy,'%)'];
      sy  = ['PC ',int2str(pc-1),sy];
    else
      sy  = sprintf('%5.2f',modl.ssq(pc-1,1));
      sy  = [' (',sy,'%)'];
      sy  = ['LV ',int2str(pc-1),sy];
    end
  end
  pc    = get(g(8,1),'Value');
  switch pc
  case 1 %none
    z   = [];
  otherwise
    z   = modl.loads(:,pc-1);
    if strcmp(modl.name,'PCA')
      sz  = sprintf('%5.2f',modl.ssq(pc-1,3));
      sz  = [' (',sz,'%)'];
      sz  = ['PC ',int2str(pc-1),sz];
    else
      sz  = sprintf('%5.2f',modl.ssq(pc-1,1));
      sz  = [' (',sz,'%)'];
      sz  = ['LV ',int2str(pc-1),sz];
    end
  end 

  if isempty(z)
    h     = findobj('Tag',['HighOrb',int2str(gcf)]);
    if h
      h   = get(h,'UserData');
      delete(h(:,1));
    end
    set(g(12:size(g,1),1),'Enable','on')
    if datstat
      set(g(18,1),'Enable','off')
    end
    plot(x,y,'+b')
    if son
      if ishold
        plot(x,y,'-g')
      else
        hold on, plot(x,y,'-g'), hold off
      end
    end
    h     = axis;
    if h(1)*h(2)<-0.000001
      vline(0);
    end
    if h(3)*h(4)<-0.000001
      hline(0)
    end
    s       = ' ';
    n       = length(modl.icol);
    if get(g(10,1),'Value')==2 %put numbers on
      s     = [s(ones(n,1)),int2str((modl.icol)')];
    elseif (get(g(10,1),'Value')==3)&~isempty(modl.vlbl)
      s     = [s(ones(n,1)),modl.vlbl(modl.icol,:)];
    end
    if get(g(10,1),'Value')>1
      text(x,y,s,'Fontname','geneva','Fontsize',10);
    end
    set(g(20,1),'UserData',h) %set 1st axis for zoom
  else
    set(g(12:size(g,1)-1,1),'Enable','off')
    plot3(x,y,z,'+b')
    s       = ' ';
    n       = length(modl.icol);
    if get(g(10,1),'Value')==2 %put numbers on
      s     = [s(ones(n,1)),int2str((modl.icol)')];
    elseif (get(g(10,1),'Value')==3)&~isempty(modl.vlbl)
      s     = [s(ones(n,1)),modl.vlbl(modl.icol,:)];    
    end
    if get(g(10,1),'Value')>1
      text(x,y,z,s,'Fontname','geneva','Fontsize',10);
    end

    drop  = 1;
    if drop==1
      h   = axis; axis(h)
      if ishold
        for jj=1:length(z)
          plot3([1 1]*x(jj),[1 1]*y(jj),[h(5) z(jj)],'-c')
        end
      else
        hold on
        for jj=1:length(z)
          plot3([1 1]*x(jj),[1 1]*y(jj),[h(5) z(jj)],'-c')
        end    
        hold off
      end
    end
    grid on
    %highorb
  end
  xlabel(sx)
  ylabel(sy)
  title('Loads Plot')
  if z
    zlabel(sz)
  end
  v     = axis;
  set(g(20,1),'UserData',v)
  set(g(3,1),'Enable','off')
case 'scrraw'
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  x      = get(z(length(z)),'xdata');
  y      = get(z(length(z)),'ydata');
  jj     = sampidr(x,y);
  if ishold
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
    hold off
  end
  s      = ['pcaplots(''scrmarkdel'',',as,')'];
  z      = get(gcf,'position');
  y      = figure('NumberTitle','off', ...
    'Name','Plot of Raw Data','Menu','none', ...
    'Position',[z(1) z(2)-10 380 285], ...
    'UserData',h,'CloseRequestFcn',s,'Tag',int2str(gcf));
  x      = get(f(1,1),'UserData');
  x      = x(modl.irow(1,jj),:);
  plot([1:length(x)],x,'+b',[1:length(x)],x,'-c')
  xlabel('Variable Number')
  ylabel('Measured Value')
  title(['Raw Data for Sample ',int2str(modl.irow(1,jj))])
  h      = axis;
  if h(1)*h(2)<-0.000001
    vline(0);
  end
  if h(3)*h(4)<-0.000001
    hline(0)
  end
  zoompls
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'lodraw'
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  x      = get(z(length(z)),'xdata');
  y      = get(z(length(z)),'ydata');
  jj     = sampidr(x,y);
  if ishold
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
    hold off
  end
  s      = ['pcaplots(''lodmarkdel'',',as,')'];
  z      = get(gcf,'position');
  y      = figure('NumberTitle','off', ...
    'Name','Plot of Raw Data','Menu','none', ...
    'Position',[z(1) z(2)-10 380 285], ...
    'UserData',h,'CloseRequestFcn',s,'Tag',int2str(gcf));
  x      = get(f(1,1),'UserData');
  x      = x(:,jj);
  plot([1:length(x)],x,'+b',[1:length(x)],x,'-c')
  xlabel('Sample Number')
  ylabel('Measured Value')
  title(['Raw Data for Variable ',int2str(jj)])
  h     = axis;
  if h(1)*h(2)<-0.000001
    vline(0);
  end
  if h(3)*h(4)<-0.000001
    hline(0)
  end
  zoompls
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'scrdel'
  g      = get(findobj('Name','Plot Scores','Tag',as),'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  z      = z(length(z));
  x      = get(z,'xdata');
  y      = get(z,'ydata');
  jj     = sampidr(x,y);     %indice in plot
  if ishold
    h    = plot(x(jj),y(jj),'*k','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'*k','MarkerSize',10);
    hold off
  end
  cndlgpls(modl.irow(1,jj),g(18,1),'sample')
  if strcmp(get(g(18,1),'Userdata'),'yes')
    jk          = modl.irow(1,jj);
    modl.irow   = delsamps(modl.irow',jj)';
    modl.scores = delsamps(modl.scores,jj);
    modl.tsq    = delsamps(modl.tsq,jj);
    modl.res    = delsamps(modl.res,jj);
    modl.slbl   = delsamps(modl.slbl,jj);
    if size(x,2)>size(x,1)
      set(z,'xdata',delsamps(x',jj)','ydata',delsamps(y',jj)')
    else
      set(z,'xdata',delsamps(x,jj),'ydata',delsamps(y,jj))
    end
    if ~isempty(modl.drow)
      if isempty(find(modl.drow==jk))
        modl.drow = [modl.drow, jk];
        stat.modl = 'none';
        set(b(1,1),'UserData',stat)
        pcagui('nothing',fighand)
      end
    else
      modl.drow = jk;
      stat.modl = 'none';
      set(b(1,1),'UserData',stat)
      pcagui('nothing',fighand)
    end
  else
    delete(h)
  end
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'scrqcon'
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  x      = get(z(length(z)),'xdata');
  y      = get(z(length(z)),'ydata');
  jj     = sampidr(x,y);
  if ishold
    h    = plot(x(jj),y(jj),'sb','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'sb','MarkerSize',10);
    hold off
  end
  s      = ['pcaplots(''scrmarkdel'',',as,')'];
  z      = get(gcf,'position');
  y      = figure('NumberTitle','off', ...
    'Name','Q Residual Contributions','Menu','none', ...
    'Position',[z(1)+5 z(2)-15 380 285], ...
    'UserData',h,'CloseRequestFcn',s,'Tag',int2str(gcf));
  x      = get(f(1,1),'UserData'); %raw
  x      = x(modl.irow(jj),:);
  z      = get(f(2,1),'UserData'); %modl
  switch z.scale
  case 'auto'
    x    = scale(x,z.means,z.stds);
  case 'mean'
    x    = scale(x,z.means);
  end
  z      = z.loads;
  [x,z]  = resmtx(x,z);
  bar([1:length(x)],x,'b')
  xlabel('Variable Number')
  ylabel('Q Residual Contribution')
  if ~datstat
    jj   = modl.irow(1,jj);
  end
  title(['Sample ',int2str(jj),' Q Residual = ',num2str(z)])
  if modl.vlbl
    y    = find(x<0);
    z    = axis;
    z2   = z(4)-max(x);
    z2   = min([z2 z(4)]');
    z3   = size(modl.vlbl,2)*0.04*(z(4)-z(3));
    if z3>z2
      z(4) = z3-z2+z(4);
      axis(z)
    end
    x(y) = zeros(1,length(y));
    x    = x+0.01*z(4)*ones(1,length(x));
    text([1:length(x)],x,modl.vlbl,'rotation',90);
  end
  hline(0)
  zoompls
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'lodtcon' %varcap
  x      = get(f(1,1),'UserData'); %raw data
  x      = x(modl.irow,modl.icol);
  switch modl.scale
  case 'auto'
    x    = scale(x,modl.means,modl.stds);
  case 'mean'
    x    = scale(x,modl.means);
  end
  figure
  if isempty(modl.vlbl)
    varcap(x,modl.loads);
  else
    varcap(x,modl.loads,[],modl.vlbl);
  end
case 'scrtcon'
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  x      = get(z(length(z)),'xdata');
  y      = get(z(length(z)),'ydata');
  jj     = sampidr(x,y);
  if ishold
    h    = plot(x(jj),y(jj),'db','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'db','MarkerSize',10);
    hold off
  end
  s      = ['pcaplots(''scrmarkdel'',',as,')'];
  z      = get(gcf,'position');
  y      = figure('NumberTitle','off', ...
    'Name','Hotelling T^2 Contributions','Menu','none', ...
    'Position',[z(1)+5 z(2)-15 380 285], ...
    'UserData',h,'CloseRequestFcn',s,'Tag',int2str(gcf));
  x      = get(f(1,1),'UserData'); %raw
  x      = x(modl.irow(jj),:);
  z      = get(f(2,1),'UserData'); %modl
  switch z.scale
  case 'auto'
    x    = scale(x,z.means,z.stds);
  case 'mean'
    x    = scale(x,z.means);
  end
  y      = z.ssq;
  z      = z.loads;
  [x,z]  = tsqmtx(x,z,y);
  bar([1:length(x)],x,'b')
  xlabel('Variable Number')
  ylabel('Hotelling T^2 Contribution')
  if ~datstat
    jj   = modl.irow(1,jj);
  end
  title(['Sample ',int2str(jj),' Hotelling T^2 = ',num2str(z)])
  if modl.vlbl
    y    = find(x<0);
    z    = axis;
    z2   = z(4)-max(x);
    z2   = min([z2 z(4)]');
    z3   = size(modl.vlbl,2)*0.04*(z(4)-z(3));
    if z3>z2
      z(4) = z3-z2+z(4);
      axis(z)
    end
    x(y) = zeros(1,length(y));
    x    = x+0.01*z(4)*ones(1,length(x));
    text([1:length(x)],x,modl.vlbl,'rotation',90);
  end
  hline(0)
  zoompls
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'scrinfo'
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  z      = z(length(z));
  x      = get(z,'xdata');
  y      = get(z,'ydata');
  jj     = sampidr(x,y);
  if ishold
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
    hold off
  end
  s      = ['pcaplots(''scrmarkdel'',',as,')'];
  z      = get(gcf,'position');
  y      = figure('NumberTitle','off', ...
    'Name','Sample Info','Color',[0 0 0],'Menu','none', ...
    'Position',[z(1)+35 z(2)-40 220 150], ...
    'UserData',h,'CloseRequestFcn',s,'Tag',int2str(gcf));
  x      = uicontrol('Parent',y,'BackgroundColor',[1 1 1], ...
    'Style','text','Position',[3 3 214 144], ...
    'FontName','geneva','FontSize',10, ...
    'HorizontalAlignment','left');
  set(x,'Units','normalized')
  if datstat
    if isempty(test.slbl)
      s  = ' ';
    else
      s  = test.slbl(jj,:);
    end
    y1   = ['Q Residual    = ',num2str(test.res(jj))];
    z    = ['Hotelling T^2 = ',num2str(test.tsq(jj))];
  else
    if isempty(modl.slbl)
      s  = ' ';
    else
      s  = modl.slbl(jj,:);
    end
    y1   = ['Q Residual    = ',num2str(modl.res(jj))];
    z    = ['Hotelling T^2 = ',num2str(modl.tsq(jj))];
    jj   = modl.irow(1,jj);
  end
  if ~get(g(13,1),'value')
    y2     = [' (95% limit   = ',num2str(modl.reslim),')'];
    z2     = [' (95% limit   = ',num2str(modl.tsqlim),')'];
  else
    s2     = get(g(12,1),'string');
    s3     = str2num(s2);
    s4     = reslim(get(f(4,1),'UserData'),modl.ssq(:,2),s3);
    s3     = tsqlim(length(modl.irow),get(f(4,1),'UserData'),s3);
    y2     = [' (',s2,'% limit   = ',num2str(s4),')'];
    z2     = [' (',s2,'% limit   = ',num2str(s3),')']; 
  end
  z      = str2mat(['Sample ',int2str(jj)],s,y1,y2,z,z2);
  set(x,'String',z)
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'scrmarkdel'
  h    = findobj('Name','Plot Scores','Tag',as);  
  if h
    h    = get(gcf,'UserData');
  end
  if ishandle(h)
    delete(h)
    closereq
  else
    closereq
  end
case 'lodmarkdel'
  h    = findobj('Name','Plot Loads','Tag',as);
  if h
    h    = get(gcf,'UserData'); delete(h)
  end
  if ishandle(h)
    delete(h)
    closereq
  else
    closereq
  end
case 'lodinfo'
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  x      = get(z(length(z)),'xdata');
  y      = get(z(length(z)),'ydata');
  jj     = sampidr(x,y);
  if ishold
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'xb','MarkerSize',10);
    hold off
  end
  s      = ['pcaplots(''lodmarkdel'',',as,')'];
  z      = get(gcf,'position');
  y      = figure('NumberTitle','off', ...
    'Name','Variable Info','Color',[0 0 0], ...
    'Position',[z(1)+35 z(2)-40 220 150], ...
    'Menu','none','Tag',int2str(gcf), ...
    'UserData',h,'CloseRequestFcn',s);
  x = uicontrol('Parent',y,'BackgroundColor',[1 1 1], ...
    'Style','text','Position',[3 3 214 144], ...
    'FontName','geneva','FontSize',10, ...
    'HorizontalAlignment','left');
  set(x,'Units','normalized')
  if isempty(modl.vlbl)
    s    = ' ';
  else
    s    = modl.vlbl(jj,:);
  end
  jj     = modl.icol(1,jj);
  z = str2mat(['Variable ',int2str(jj)],s);
  y      = get(f(1,1),'UserData');
  y      = y(:,jj);
  s1     = sprintf('mean = %g',mean(y));
  s2     = sprintf('std  = %g',std(y));
  z = str2mat(z,s1,s2); 
  set(x,'String',z)
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'loddel'
%not tested
  g      = get(gcf,'UserData');
  set(g(1:size(g,1),1),'Enable','off')
  z      = get(gca,'children');
  x      = get(z(length(z)),'xdata');
  y      = get(z(length(z)),'ydata');
  jj     = sampidr(x,y);     %indice in plot
  if ishold
    h    = plot(x(jj),y(jj),'*k','MarkerSize',10);
  else
    hold on
    h    = plot(x(jj),y(jj),'*k','MarkerSize',10);
    hold off
  end
  jj     = modl.icol(1,jj);  %variable number
  cndlgpls(jj,g(18,1),'variable')
  if strcmp(get(g(18,1),'Userdata'),'yes')
    modl.dcol = [modl.dcol, jj];
    stat.modl = 'none';
    pcagui('nothing',fighand)
  else
    delete(h)
  end
  set(g(1:size(g,1),1),'Enable','on')
  if datstat
    set(g(18,1),'Enable','off')
  end
case 'limitchk'
  g = get(gcf,'UserData');
  set(g(3,1),'Enable','on')
  if get(g(13,1),'Value')
    set(g(12,1),'Enable','on')
  else
    set(g(12,1),'Enable','off')
  end
case 'g3on'
  g = get(gcf,'UserData');
  set(g(3,1),'Enable','on')
end

set(f(2,1),'UserData',modl)
set(b(1,1),'UserData',stat)

⌨️ 快捷键说明

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