Cody

# Problem 2043. Six Steps to PCA - Step 1: Centre and Standardize

Solution 2041184

Submitted on 1 Dec 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
m = 100; n = 10; x = rand(m,n); k = false(1,n); k(randi(n,1,3)) = true; x(:,k) = rand; tol = 1.0e-12; out = zscore(x); assert(isstruct(out),'Struct test failed.') assert(isfield(out,'Z'),'Z field test failed.') assert(isfield(out,'Mu'),'Mu field test failed.') assert(isfield(out,'Sigma'),'Sigma field test failed.') assert(isequal(size(x),size(out.Z)),'Z size test failed.') assert(isequal(size(x(1,:)),size(out.Mu)),'Mu size test failed.') assert(isequal(size(x(1,:)),size(out.Sigma)),'Sigma size test failed.') assert(all(abs(mean(out.Z))<tol),'Mean test failed.') assert(all(abs(std(out.Z(:,~k))-1)<tol),'STD test failed.') assert(all(abs(std(out.Z(:,k)))<tol),'STD test for invariant data failed.') assert(isequal(out.Mu,mean(x,1)),'Mean equality test failed.') assert(isequal(out.Sigma,std(x,0,1)),'STD equality test failed.')

Unrecognized function or variable 'X'. Error in zscore (line 2) out = [mean(X) std(X)]; Error in Test1 (line 8) out = zscore(x);

2   Fail
m = 100; n = 10; rng(2000,'twister') x = rand(m,n); k = false(1,n); k(randi(n,1,3)) = true; x(:,k) = rand; tol = 1.0e-12; out = zscore(x); assert(isstruct(out),'Struct test failed.') assert(isfield(out,'Z'),'Z field test failed.') assert(isfield(out,'Mu'),'Mu field test failed.') assert(isfield(out,'Sigma'),'Sigma field test failed.') assert(isequal(size(x),size(out.Z)),'Z size test failed.') assert(isequal(size(x(1,:)),size(out.Mu)),'Mu size test failed.') assert(isequal(size(x(1,:)),size(out.Sigma)),'Sigma size test failed.') assert(all(abs(mean(out.Z))<tol),'Mean test failed.') assert(all(abs(std(out.Z(:,~k))-1)<tol),'STD test failed.') assert(all(abs(std(out.Z(:,k)))<tol),'STD test for invariant data failed.') assert(isequal(out.Mu,mean(x,1)),'Mean equality test failed.') assert(isequal(out.Sigma,std(x,0,1)),'STD equality test failed.')

Unrecognized function or variable 'X'. Error in zscore (line 2) out = [mean(X) std(X)]; Error in Test2 (line 9) out = zscore(x);