% Input data... Xtrain; Ytrain; Xtest; Ytest; % Compute sample covariance matrix S = cov(Xtrain'); % Note, matlab assumes each column is a variable, thus the transpose % Compute eigenvectors [U,D] = eig(S); U = fliplr(U); % eig orders eigenvectors from least to most important % Set level of approximation k = 5; Xtrain_reduced = U(:,1:k)' * Xtrain; Xtest_reduced = U(:,1:k)' * Xtest; [ccMean,ccVar] = Trainer(Xtrain_reduced,Ytrain); Acc = Tester(ccMean,ccVar,Xtest_reduced,Ytest); %%% Of course... you'll want for-loop for various k...