function [Esel,Y,L]=dimredpca(X,threshold)
%Each column is representing the data
%Each row is representing the feature
%threshold to fix the number of elements in the lower
% % dimensional space
%L is the number of elements in the lower dimensional space
M=mean(X');
temp=(X-repmat(M',1,size(X,2)));
CM=temp*temp';
[E,V]=eig(CM);
V=diag(V)/max(diag(V));
[P,Q]=find(V>=threshold);
Esel=E(:,size(E,2):-1:P(1));
L=size(Esel,2);
Y=Esel'*X;