📄 pcagui.m
字号:
set(f(2,1),'UserData',modl)
end
case 'loadslbl'
if strcmp(stat.data,'test')
s1 = test.slbl;
s2 = test.slbln;
else
s1 = modl.slbl;
s2 = modl.slbln;
end
lddlgpls(b(2,1),e(4,1),'char')
s = get(b(2,1),'UserData');
s0 = get(e(4,1),'UserData');
if (~isempty(s0))&(~strcmp(s2,s0))
if size(s,1)==size(x,1)
if strcmp(stat.data,'test')|strcmp(stat.modl,'loaded')
test.slbl = s;
test.slbln = s0;
elseif strcmp(stat.data,'new')|strcmp(stat.data,'cal')
modl.slbl = s;
modl.slbln = s0;
end
elseif ~isempty(s)
if strcmp(stat.data,'test')|strcmp(stat.modl,'loaded')
test.slbl = [];
test.slbln = [];
elseif strcmp(stat.data,'new')|strcmp(stat.data,'cal')
modl.slbl = [];
modl.slbln = [];
end
s = 'number of rows must equal number of ';
s = [s,'rows of loaded data - no labels loaded'];
erdlgpls(s,'Error on Load!')
end
end
case 'loadvlbl'
if strcmp(stat.data,'test')
s1 = test.vlbl;
s2 = test.vlbln;
else
s1 = modl.vlbl;
s2 = modl.vlbln;
end
lddlgpls(b(2,1),e(4,1),'char')
s = get(b(2,1),'UserData');
s0 = get(e(4,1),'UserData');
if (~isempty(s0))&(~strcmp(s2,s0))
if size(s,1)==size(x,2)
if strcmp(stat.data,'test')|strcmp(stat.modl,'loaded')
test.vlbl = s;
test.vlbln = s0;
elseif strcmp(stat.data,'new')|strcmp(stat.data,'cal')
modl.vlbl = s;
modl.vlbln = s0;
end
elseif ~isempty(s)
if strcmp(stat.data,'test')|strcmp(stat.modl,'loaded')
test.vlbl = [];
test.vlbln = [];
elseif strcmp(stat.data,'new')|strcmp(stat.data,'cal')
modl.vlbl = [];
modl.vlbln = [];
end
s = 'number of rows must equal number of ';
s = [s,'columns of loaded data - no labels loaded'];
erdlgpls(s,'Error on Load!')
end
end
case 'loadsscl'
if strcmp(stat.data,'test')
s1 = test.sscl;
else
s1 = modl.sscl;
end
lddlgpls(b(2,1),e(4,1),'double')
s = get(b(2,1),'UserData');
[ms,ns] = size(s);
if ms>ns
s = s';
[ms,ns] = size(s);
end
if ms>1
s = 'scale variable must be a vector';
s = [s,' - no scale loaded'];
erdlgpls(s,'Error on Load!')
else
if length(s1)==length(s)
s2 = sum(s'-s1');
else
s2 = 1;
end
if s2
if length(s)==size(x,1)
if strcmp(stat.data,'test')|strcmp(stat.modl,'loaded')
test.sscl = s;
elseif strcmp(stat.data,'new')|strcmp(stat.data,'cal')
modl.sscl = s;
end
elseif ~isempty(s)
if strcmp(stat.data,'test')|strcmp(stat.modl,'loaded')
test.sscl = [];
elseif strcmp(stat.data,'new')|strcmp(stat.data,'cal')
modl.sscl = [];
end
s = 'number of elements must equal number of ';
s = [s,'rows of loaded data - no labels loaded'];
erdlgpls(s,'Error on Load!')
end
end
end
case 'loadvscl'
s1 = modl.vscl;
lddlgpls(b(2,1),e(4,1),'double')
s = get(b(2,1),'UserData');
[ms,ns] = size(s);
if ms>ns
s = s';
[ms,ns] = size(s);
end
if ms>1
s = 'scale variable must be a vector';
s = [s,' - no scale loaded'];
erdlgpls(s,'Error on Load!')
else
if length(s1)==length(s)
s2 = sum(s'-s1');
else
s2 = 1;
end
if s2
if length(s)==size(x,2)
modl.vscl = s;
elseif ~isempty(s)
modl.vscl = [];
s = 'number of elements must equal to number of ';
s = [s,'columns of loaded data - no labels loaded'];
erdlgpls(s,'Error on Load!')
end
end
end
case 'loadmodl'
lddlgpls(f(2,1),d(4,1),'struct')
modl = get(f(2,1),'UserData');
if ~isempty(modl)
s = char(fieldnames(modl));
s1 = 'no';
for jj=1:size(s,1)
if strncmp(s(jj,:),'name',4)
s1 = 'yes';
end
end
if strcmp(s1,'no')|size(modl,1)>1|size(modl,2)>1
erdlgpls('variable not a PCA model','Error on Load Model!')
pcagui('clearmodl',a)
elseif strcmp(s1,'yes')
if strcmp(modl.name,'PCA')
stat.modl = 'loaded';
if ~strcmp(stat.data,'none')
stat.data = 'new';
end
x = size(modl.loads,2);
format = get(e(1,1),'UserData');
s = [];
for jj=1:size(modl.ssq,1)
s = [s;sprintf(format,modl.ssq(jj,:))];
end
set(e(4,1),'String',s,'Value',x)
set(e(3,1),'String',int2str(x))
set(f(4,1),'UserData',x)
set(f(3,1),'UserData',[])
elseif isempty(modl.name)
else
erdlgpls('variable not a PCA model','Error on Load Model!')
pcagui('clearmodl',a)
end
else
erdlgpls('variable not a PCA model','Error on Load Model!')
pcagui('clearmodl',a)
end
end
case 'savemat'
x = x(modl.irow,modl.icol);
if isempty(x)
erdlgpls('no data loaded to be saved','Error on Save!')
else
svdlgpls(x,'X-block');
end
case 'savetst'
if isempty(test)|isempty(test.xname)
erdlgpls('no test data to be saved','Error on Save!')
else
svdlgpls(test,'PCA test');
end
case 'savemodl'
if isempty(modl)|isempty(modl.name)
erdlgpls('no model to be saved','Error on Save!')
else
svdlgpls(modl,'PCA model');
end
case 'cleardata'
stat.data = 'none'; %'new', 'cal', 'test'
set(d(4,1),'UserData',[]) %clear x-block name
modl.xname = [];
set(f(1,1),'UserData',[]) %clear x-block data
set(f(7,1),'UserData',[]) %clear y-block data
test.scores = []; %Scores for test data
test.res = []; %Sample Q residuals for test data
test.tsq = []; %Sample Hotelling T^2 for tst data
test.sscl = []; %Sample scale
test.slbl = []; %Sample labels for test data
test.slbln = []; %Sample label name for test data
test.xname = []; %Name of loaded X-block variable
delfigs(as)
h = findobj('Name','Plot Data','Tag',as); close(h)
if ~strcmp(stat.modl,'none')
stat.modl = 'loaded';
end
set(bb(15,1),'Enable','off')
case 'clearmodl'
stat.modl = 'none'; %'calold', 'calnew', 'loaded'
modl.name = []; %PLS, SIM, PCR
modl.date = []; %Date model was created
modl.time = []; %Time model was created
modl.scores = []; %X-block scores for cal data
modl.loads = []; %X-block loadings
modl.ssq = []; %Variance information
modl.means = []; %Centering vector
modl.stds = []; %Scaling vector
modl.scale = 'auto'; %Scale Status
modl.res = []; %Sample Q residuals
modl.reslim = []; %95% conf limit for Q
modl.tsq = []; %Sample Hotelling T^2
modl.tsqlim = []; %95% conf limit for T^2
modl.irow = []; %Indices of samples used
modl.icol = []; %Indices of variables used
modl.drow = []; %Indices of samples deleted
modl.dcol = []; %Indices of variables deleted
modl.sscl = []; %Sample scale
modl.vscl = []; %Variable scale
modl.slbl = []; %Sample labels
modl.slbln = []; %Sample label name
modl.vlbl = []; %Variable labels
modl.vlbln = []; %Variable label name
modl.xname = []; %Name of loaded X-block variable
if ~strcmp(stat.data,'none')
stat.data = 'new';
[m,n] = size(get(f(1,1),'UserData'));
modl.irow = [1:m];
modl.icol = [1:n];
end
delfigs(as)
pcagui('actauto',a);
case 'exitpca'
%check to see if data edited, if so ask if save
%check to see if model changed, if so ask if save
delfigs(as)
h = findobj('Name','Plot Data','Tag',as); close(h)
closereq
%Scaling Options
case 'actnoscale'
set(bb(13:14,1),'Checked','off')
set(bb(12,1),'Checked','on')
modl.scale = 'no';
stat.modl = 'none';
if ~strcmp(stat.data,'none')
stat.data= 'new';
end
case 'actmncn'
set(bb([12 14],1),'Checked','off')
set(bb(13,1),'Checked','on')
modl.scale = 'mean';
stat.modl = 'none';
if ~strcmp(stat.data,'none')
stat.data= 'new';
end
case 'actauto'
set(bb(12:13,1),'Checked','off')
set(bb(14,1),'Checked','on')
modl.scale = 'auto';
stat.modl = 'none';
if ~strcmp(stat.data,'none')
stat.data= 'new';
end
%Button Callbacks
case 'calculate'
delfigs(as)
x = get(f(1,1),'UserData');
if ~isempty(x)
if ~isempty(modl)
if ~isempty(modl.drow)
jk = [];
for jj=1:length(modl.drow)
jk = [jk,find(modl.irow==modl.drow(jj))];
end
modl.irow = delsamps(modl.irow',jk)';
end
x = x(modl.irow,modl.icol);
set(bb(8,1),'Enable','on');
[m,n] = size(x);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -