function [pcaDataset] = myPCA(dataset) % this function applies the PCA transformation % firstly standardize data columnStdDevs = std(dataset(:,1:(size(dataset,2)-1))); standardizedData = dataset(:,1:(size(dataset,2)-1)) ./ repmat(columnStdDevs,size(dataset,1),1); % apply PCA to get coefficients [coefs,scores,variances,t2] = princomp(standardizedData); % multiply actual data with coefficients pcaDataset = [(standardizedData * coefs),dataset(:,size(dataset,2))]; end