Error using tabular/permute and Error in median (line 186)

3 Ansichten (letzte 30 Tage)
Suman Ahmed
Suman Ahmed am 5 Dez. 2020
load dataassign5.mat;
%Input data from TE Chemical Process
X=dataassign5(1:535,1:6); %6 continuous variable
% find dimension of matrix, n=number of rows, p=number of columns/variables
[n,p] = size(X);
ran = min(size(X,1),size(X,2));
if p>ran
p=ran;
end
c= median(X); %median
C=repmat(c,n,1);
d=std(X); %standard deviation
D=repmat(d,n,1);
X=(X-C)./D;
% diagonalisation
[Tmat,E,L] = svd(X,0);
eigmat = E;
% eigenvalues
Efull = diag(E).^2/(n-1);
exp_var = Efull/sum(Efull);
E = Efull(1:p);
exp_var = exp_var(1:p);
for k=1:p
cum_var(k) = sum(exp_var(1:k));
end
%SCREE Plot
figure (01)
bar(exp_var);
title('SCREE Plot')
xlabel('No of PCs');
ylabel('Variance');
% no of principal components
a=20;
% loadings,L and scores,T
L = L(:,1:a);
T = X*L;
% T2 hotelling
I=E';
I=I(1,1:a);
I=diag(I);
I_inv=(I)^(-1/2);
for i=1:n
Tcont(i,:) = (((X(i,:)*L)*I_inv)*L');
Thot(i) = Tcont(i,:)*Tcont(i,:)';
end
% Q residuals
Xmod = T*L';
Err = X - Xmod;
I1=1;
I1(1:p)=I1;
I1=diag(I1);
for i=1:n
Qcont(i,:)= X(i,:)*(I1-L*L');
Qres(i) = Qcont(i,:)*X(i,:)';
end
% T2 limit
lev_conf = 0.99;
F = finv(0.99,a,n-a);
tlim = a*(n - 1)/(n - a)*F;
% Q limit
t1 = sum(E((a+1):end).^1);
t2 = sum(E((a+1):end).^2);
t3 = sum(E((a+1):end).^3);
ho = 1 - (2*t1*t3)/(3*t2^2);
ca = norminv(0.95, 0, 1);
term1 = (ho*ca*(2*t2)^0.5)/t1;
term2 = (t2*ho*(ho - 1))/(t1^2);
qlim = t1*(term1 + 1 + term2)^(1/ho);
%Plot
% read number of samples
M=1:n;
% read T2 critical value
S (1:n)=tlim;
% read Q critical value
N (1:n)=qlim;
%T2 control chart in NOC
figure (02)
plot(M,S,M,Thot);
axis([0,n,0,tlim+20]);
title('T^{2} Control Chart in Normal Operating Condition');
xlabel('Sample No');
ylabel('T^{2} Value');
Thresholdt2= tlim;
%False alarm rate T2
for i=1:n
b(i)=Thot(i)>tlim;
end
fat2=sum(b); %total false alarms
FARt2=fat2/n*100;
%SPE control chart in NOC
figure (03)
plot(M,N,M,Qres);
axis([0,n,0,qlim+5]);
title('SPE Control Chart in Normal Operating Condition');
xlabel('Sample No');
ylabel('SPE Value');
Thresholdq= qlim;
%False alarm rate SPE
for i=1:n
b1(i)=Qres(i)>qlim;
end
faspe=sum(b1); %total false alarms
FARspe=faspe/n*100;

Antworten (1)

Christine Tobler
Christine Tobler am 7 Dez. 2020
Applying median to a table directly is not supported.
Either apply median to a specific variable of the table
>> t = table([3; 4; 5], [2; 4; 1])
t =
3×2 table
Var1 Var2
____ ____
3 2
4 4
5 1
>> median(t.Var1)
ans =
4
or use varfun to apply the same function to all variables in the table.
>> varfun(@median, t)
ans =
1×2 table
median_Var1 median_Var2
___________ ___________
4 2

Kategorien

Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by