clear all;
DATA=load('D:0.m');
DATA=double(DATA);
DATA=DATA';
TESTDATA=load('D:14f.m');
TESTDATA=double(TESTDATA);
% DATA=load('D:正常.txt');
% DATA=double(DATA);
% DATA=DATA(:,3:12);
% TESTDATA=load('D:异常.txt');
% TESTDATA=double(TESTDATA);
% TESTDATA=TESTDATA(:,3:12);
[Kp,T2]=tztq(DATA,TESTDATA);
function [contribution,T2,SPE,t2cl,s_cl] = PCA_model(Xtrain,Xtest)
X_mean = mean(Xtrain);
X_std = std(Xtrain);
[X_row ,X_col]= size(Xtrain);
for i = 1:X_col
Xtrain(:,i) = (Xtrain(:,i)-X_mean(i))./X_std(i);
Xtest(:,i) = (Xtest(:,i)-X_mean(i))./X_std(i);
end
[U,S,V]=svd(Xtrain./sqrt(size(Xtrain,1)-1),0);
D= S^2;
lamda=diag(D);