function [D,E,z]=pca(x)
x=x';

x=x-repmat(mean(x,1),[size(x,1) 1]);
x=x./repmat(std(x,1)+1e-15,[size(x,1) 1]);

[coeff, z] = princomp(x);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PCA calculation wihtout the statistics toolbox %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% S=cov(x);
% % D=diag(std(x)+1e-15);
% % R=inv(D)*S*inv(D);
% [U,L]=eig(S);
% z=(U'*x')';
% 
% [Y,I] = sort(max(L,[],1));                    
% I=flipud(I')';
% 
% for n=1:length(I)                         
%     z_sort(:,n)=z(:,I(n));                           
% end                                              
% z=z_sort; 

D=[]; E=[];
