function [Esel,Y,L]=dimredlda(X,split,thresh) 
%Each column of the variable X represents the data %Each row of the variable represents the feature %split represnts the number of vectors in the individual classes.length of %the split gives the number of classes %thresh represents the threshold to fix the number of elements %in the lower dimensional space %L is the number of elements in the lower dimensional space 
split=[1 split]; SB=0;
MEANDATA=[]; 
for i=1:1:length(split)-1 
    DATA=X(:,split(i):1:split(i+1)); 
    n=size(DATA,2); M=mean(DATA'); 
    temp1=(DATA-repmat(M',1,size(DATA,2))); 
    temp2=temp1*temp1'; 
    SB=SB+n*temp2; MEANDATA=[MEANDATA M]; 
end
M=mean(MEANDATA');
temp3=(MEANDATA-repmat(M',1,size(MEANDATA,2)));
SW=temp3*temp3';
SW=real(SW); 
[E,V]=eig(pinv(SW)*SB); 
V=real(V); 
V=diag(V)/max(diag(V)); 
[P,Q]=find(V>=thresh); 
Esel=E(:,size(E,2):-1:P(1)); 
L=size(Esel,2); 
Y=Esel'*X; 