close all;
clear all;

cl=[1    0    0
    0    0    1
    0    1    0
    0    1    1
    1    0    1
    0.5  0    0
    0.5  0.5  0.5
    0.25  0   0.5];


load F:\MatlabCodes\Normal_Cg_TLE_AllPatientsVector %AllPatientsVector
Normal_Vector_Cg=AllPatientsVector;

load Cg_BiTLE_AllPatientsVector  %AllPatientsVector
BI_TLE_Vector_Cg=AllPatientsVector;

BI_pats=pats;

load F:\MatlabCodes\Cg_TLE_AllPatientsVector %AllPatientsVector pats
TLE_Vector_Cg=AllPatientsVector;
Uni_pats=pats;

side_TLE=  ['L'
    'R'
    'L'
    'L'
    'R'
    'R'
    'L'
    'L'
    'L'
    'L'
    'R'
    'R'
    'L'
    'L'
    'R'
    'L'
    'R'
    'R'
    'L'
    'R'
    'R'
    'R'
    'R'
    'L'];
side=side_TLE;
%   str =['mean_All_' predictor];
%     tmp=eval(str);

index='FA';   %,'FA' 'MD', 'AD', 'RD', 'NV';

switch index
    case 'FA'
        IND=1;
        val=0.2;
    case 'MD'
        IND=3;
        val=3.5e-04;
    case 'AD'
        val=3.5e-04;
        IND=5;
    case 'RD'
        IND=7;
        val=3.5e-04;
    case'NV'
        IND=9;
        val=3500;
end

%----------------------------------------
Cg_PL_TLE=TLE_Vector_Cg(IND:9:end,1);
Cg_PR_TLE=TLE_Vector_Cg(IND:9:end,4);
Cg_SL_TLE=TLE_Vector_Cg(IND:9:end,2);
Cg_SR_TLE=TLE_Vector_Cg(IND:9:end,5);
Cg_AL_TLE=TLE_Vector_Cg(IND:9:end,3);
Cg_AR_TLE=TLE_Vector_Cg(IND:9:end,6);

Cg_L_TLE=TLE_Vector_Cg(IND:9:end,7);
Cg_R_TLE=TLE_Vector_Cg(IND:9:end,8);
Cg_P_TLE=TLE_Vector_Cg(IND:9:end,9);
Cg_S_TLE=TLE_Vector_Cg(IND:9:end,10);
Cg_A_TLE=TLE_Vector_Cg(IND:9:end,11);
Cg_TLE=TLE_Vector_Cg(IND:9:end,12);

%----------------------------------------
Cg_PL_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,1);
Cg_PR_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,4);
Cg_SL_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,2);
Cg_SR_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,5);
Cg_AL_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,3);
Cg_AR_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,6);

Cg_L_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,7);
Cg_R_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,8);
Cg_P_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,9);
Cg_S_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,10);
Cg_A_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,11);
Cg_BI_TLE=BI_TLE_Vector_Cg(IND:9:end,12);

%----------------------------------------
Cg_PL_Normal=Normal_Vector_Cg(IND:9:end,1);
Cg_PR_Normal=Normal_Vector_Cg(IND:9:end,4);
Cg_SL_Normal=Normal_Vector_Cg(IND:9:end,2);
Cg_SR_Normal=Normal_Vector_Cg(IND:9:end,5);
Cg_AL_Normal=Normal_Vector_Cg(IND:9:end,3);
Cg_AR_Normal=Normal_Vector_Cg(IND:9:end,6);

Cg_L_Normal=Normal_Vector_Cg(IND:9:end,7);
Cg_R_Normal=Normal_Vector_Cg(IND:9:end,8);
Cg_P_Normal=Normal_Vector_Cg(IND:9:end,9);
Cg_S_Normal=Normal_Vector_Cg(IND:9:end,10);
Cg_A_Normal=Normal_Vector_Cg(IND:9:end,11);
Cg_Normal=Normal_Vector_Cg(IND:9:end,12);


Lat_Cg_TLE=repmat('R', size(Cg_PL_TLE));
Lat_Cg_TLE(Cg_PL_TLE < Cg_PR_TLE)='L';

Cg_PL_TLE_R=Cg_PL_TLE(side=='R');
Cg_SL_TLE_R=Cg_SL_TLE(side=='R');
Cg_AL_TLE_R=Cg_AL_TLE(side=='R');
Cg_PR_TLE_R=Cg_PR_TLE(side=='R');
Cg_SR_TLE_R=Cg_SR_TLE(side=='R');
Cg_AR_TLE_R=Cg_AR_TLE(side=='R');

Cg_L_TLE_R=Cg_L_TLE(side=='R');
Cg_R_TLE_R=Cg_R_TLE(side=='R');
Cg_P_TLE_R=Cg_P_TLE(side=='R');
Cg_S_TLE_R=Cg_S_TLE(side=='R');
Cg_A_TLE_R=Cg_A_TLE(side=='R');
Cg_TLE_R=Cg_TLE(side=='R');

Cg_PL_TLE_L=Cg_PL_TLE(side=='L');
Cg_SL_TLE_L=Cg_SL_TLE(side=='L');
Cg_AL_TLE_L=Cg_AL_TLE(side=='L');
Cg_PR_TLE_L=Cg_PR_TLE(side=='L');
Cg_SR_TLE_L=Cg_SR_TLE(side=='L');
Cg_AR_TLE_L=Cg_AR_TLE(side=='L');

Cg_L_TLE_L=Cg_L_TLE(side=='L');
Cg_R_TLE_L=Cg_R_TLE(side=='L');
Cg_P_TLE_L=Cg_P_TLE(side=='L');
Cg_S_TLE_L=Cg_S_TLE(side=='L');
Cg_A_TLE_L=Cg_A_TLE(side=='L');
Cg_TLE_L=Cg_TLE(side=='L');


%-------------------------------Fx---------------------

load F:\MatlabCodes\Fx_Normal_TLE_AllPatientsVector %AllPatientsVector
Normal_Vector_Fx=AllPatientsVector;

load Fx_BiTLE_AllPatientsVector %AllPatientsVector
BI_TLE_Vector_Fx=AllPatientsVector;

load F:\MatlabCodes\Fx_TLE_AllPatientsVector %AllPatientsVector pats
TLE_Vector_Fx=AllPatientsVector;

Fx_Ant_TLE=TLE_Vector_Fx(IND:9:end,1);
Fx_L_TLE=TLE_Vector_Fx(IND:9:end,3);%./(TLE_Vector_Fx(IND:9:end,3)+TLE_Vector_Fx(IND:9:end,2));
Fx_R_TLE=TLE_Vector_Fx(IND:9:end,2);%./(TLE_Vector_Fx(IND:9:end,3)+TLE_Vector_Fx(IND:9:end,2));
Fx_TLE=TLE_Vector_Fx(IND:9:end,4);

Fx_Ant_BI_TLE=BI_TLE_Vector_Fx(IND:9:end,1);
Fx_L_BI_TLE=BI_TLE_Vector_Fx(IND:9:end,3);%./(BI_TLE_Vector_Fx(IND:9:end,2)+BI_TLE_Vector_Fx(IND:9:end,3));
Fx_R_BI_TLE=BI_TLE_Vector_Fx(IND:9:end,2);%./(BI_TLE_Vector_Fx(IND:9:end,2)+BI_TLE_Vector_Fx(IND:9:end,3));
Fx_BI_TLE=BI_TLE_Vector_Fx(IND:9:end,4);

Fx_Ant_Normal=Normal_Vector_Fx(IND:9:end,1);
Fx_L_Normal=Normal_Vector_Fx(IND:9:end,3);%./(Normal_Vector_Fx(IND:9:end,3)+Normal_Vector_Fx(IND:9:end,2));
Fx_R_Normal=Normal_Vector_Fx(IND:9:end,2);%./(Normal_Vector_Fx(IND:9:end,3)+Normal_Vector_Fx(IND:9:end,2));
Fx_Normal=Normal_Vector_Fx(IND:9:end,4);

Lat_Fx_TLE=repmat('R', size(Fx_L_TLE));
Lat_Fx_TLE(Fx_L_TLE < Fx_R_TLE)='L';

Fx_Ant_TLE_R=Fx_Ant_TLE(side=='R');
Fx_L_TLE_R=Fx_L_TLE(side=='R');
Fx_R_TLE_R=Fx_R_TLE(side=='R');
Fx_TLE_R=Fx_TLE(side=='R');

Fx_Ant_TLE_L=Fx_Ant_TLE(side=='L');
Fx_L_TLE_L=Fx_L_TLE(side=='L');
Fx_R_TLE_L=Fx_R_TLE(side=='L');
Fx_TLE_L=Fx_TLE(side=='L');


Fx_TickVec=[1:3:12];

%--------------------------CC-------------------------------------

load F:\MatlabCodes\Normal_CC_AllPatientsVector %AllPatientsVector
Normal_Vector_CC=AllPatientsVector;

load F:\MatlabCodes\BL_TLE_CC_AllPatientsVector %AllPatientsVector
BI_TLE_Vector_CC=AllPatientsVector;

load F:\MatlabCodes\TLE_CC_AllPatientsVector %AllPatientsVector
TLE_Vector_CC=AllPatientsVector;

CC_L_TLE=TLE_Vector_CC(IND:9:end,23);
CC_R_TLE=TLE_Vector_CC(IND:9:end,24);
Bd_L_TLE=TLE_Vector_CC(IND:9:end,21);
Bd_R_TLE=TLE_Vector_CC(IND:9:end,22);
Ge_L_TLE=TLE_Vector_CC(IND:9:end,1);
Ge_R_TLE=TLE_Vector_CC(IND:9:end,2);
Sp_L_TLE=TLE_Vector_CC(IND:9:end,11);
Sp_R_TLE=TLE_Vector_CC(IND:9:end,12);
Is_L_TLE=TLE_Vector_CC(IND:9:end,9);
Is_R_TLE=TLE_Vector_CC(IND:9:end,10);

CC_L_BI_TLE=BI_TLE_Vector_CC(IND:9:end,23);
CC_R_BI_TLE=BI_TLE_Vector_CC(IND:9:end,24);
Bd_L_BI_TLE=BI_TLE_Vector_CC(IND:9:end,21);
Bd_R_BI_TLE=BI_TLE_Vector_CC(IND:9:end,22);
Ge_L_BI_TLE=BI_TLE_Vector_CC(IND:9:end,1);
Ge_R_BI_TLE=BI_TLE_Vector_CC(IND:9:end,2);
Sp_L_BI_TLE=BI_TLE_Vector_CC(IND:9:end,11);
Sp_R_BI_TLE=BI_TLE_Vector_CC(IND:9:end,12);
Is_L_BI_TLE=BI_TLE_Vector_CC(IND:9:end,9);
Is_R_BI_TLE=BI_TLE_Vector_CC(IND:9:end,10);

Lat_CC_TLE=repmat('R', size(CC_L_TLE));
Lat_CC_TLE(CC_L_TLE < CC_R_TLE)='L';

Lat_Bd_TLE=repmat('R', size(Bd_L_TLE));
Lat_Bd_TLE(Bd_L_TLE < Bd_R_TLE)='L';

Lat_Ge_TLE=repmat('R', size(Ge_L_TLE));
Lat_Ge_TLE(Ge_L_TLE < Ge_R_TLE)='L';

Lat_Is_TLE=repmat('R', size(Is_L_TLE));
Lat_Is_TLE(Is_L_TLE < Is_R_TLE)='L';


CC_TLE=TLE_Vector_CC(IND:9:end,20);
CC_L_TLE=TLE_Vector_CC(IND:9:end,23);
CC_R_TLE=TLE_Vector_CC(IND:9:end,24);
Bd_TLE=TLE_Vector_CC(IND:9:end,19);
Ge_TLE=TLE_Vector_CC(IND:9:end,13);
Sp_TLE=TLE_Vector_CC(IND:9:end,18);
Rb_TLE=TLE_Vector_CC(IND:9:end,14);
Am_TLE=TLE_Vector_CC(IND:9:end,15);
Pm_TLE=TLE_Vector_CC(IND:9:end,16);
Is_TLE=TLE_Vector_CC(IND:9:end,17);


Sp_Bd_TLE=Sp_TLE-Bd_TLE;

CC_TLE_R=CC_TLE(side=='R');
CC_R_TLE_R=CC_R_TLE(side=='R');
CC_L_TLE_R=CC_L_TLE(side=='R');
Sp_R_TLE_R=Sp_R_TLE(side=='R');
Sp_L_TLE_R=Sp_L_TLE(side=='R');

Bd_TLE_R=Bd_TLE(side=='R');
Ge_TLE_R=Ge_TLE(side=='R');
Sp_TLE_R=Sp_TLE(side=='R');
Rb_TLE_R=Rb_TLE(side=='R');
Am_TLE_R=Am_TLE(side=='R');
Pm_TLE_R=Pm_TLE(side=='R');
Is_TLE_R=Is_TLE(side=='R');

Sp_Bd_TLE_R=Sp_Bd_TLE(side=='R');

CC_TLE_L=CC_TLE(side=='L');
CC_R_TLE_L=CC_R_TLE(side=='L');
CC_L_TLE_L=CC_L_TLE(side=='L');
Sp_R_TLE_L=Sp_R_TLE(side=='L');
Sp_L_TLE_L=Sp_L_TLE(side=='L');

Bd_TLE_L=Bd_TLE(side=='L');
Ge_TLE_L=Ge_TLE(side=='L');
Sp_TLE_L=Sp_TLE(side=='L');
Rb_TLE_L=Rb_TLE(side=='L');
Am_TLE_L=Am_TLE(side=='L');
Pm_TLE_L=Pm_TLE(side=='L');
Is_TLE_L=Is_TLE(side=='L');

Sp_Bd_TLE_L=Sp_Bd_TLE(side=='L');

CC_BI_TLE=BI_TLE_Vector_CC(IND:9:end,20);
CC_L_BI_TLE=BI_TLE_Vector_CC(IND:9:end,23);
CC_R_BI_TLE=BI_TLE_Vector_CC(IND:9:end,24);
Bd_BI_TLE=BI_TLE_Vector_CC(IND:9:end,19);
Ge_BI_TLE=BI_TLE_Vector_CC(IND:9:end,13);
Sp_BI_TLE=BI_TLE_Vector_CC(IND:9:end,18);
Rb_BI_TLE=BI_TLE_Vector_CC(IND:9:end,14);
Am_BI_TLE=BI_TLE_Vector_CC(IND:9:end,15);
Pm_BI_TLE=BI_TLE_Vector_CC(IND:9:end,16);
Is_BI_TLE=BI_TLE_Vector_CC(IND:9:end,17);


CC_Normal=Normal_Vector_CC(IND:9:end,20);
CC_L_Normal=Normal_Vector_CC(IND:9:end,23);
CC_R_Normal=Normal_Vector_CC(IND:9:end,24);
Bd_Normal=Normal_Vector_CC(IND:9:end,19);
Ge_Normal=Normal_Vector_CC(IND:9:end,13);
Sp_Normal=Normal_Vector_CC(IND:9:end,18);
Rb_Normal=Normal_Vector_CC(IND:9:end,14);
Am_Normal=Normal_Vector_CC(IND:9:end,15);
Pm_Normal=Normal_Vector_CC(IND:9:end,16);
Is_Normal=Normal_Vector_CC(IND:9:end,17);

 
% for i=1:10
%     if H_TLE_N(i)    
%         text('String',['p=' num2str(P_TLE_N(i),1)], 'Position' , [CC_TickVec(i)+0.25,m_CC_TLE_Vec(i)],'color' ,'K');
%         text('String','*', 'Position' , [CC_TickVec(i)+0.1,m_CC_TLE_Vec(i)],'color' ,'K','fontsize',24,'fontweight','b');
%     end
%     if H_TLE_R_N(i)    
%         text('String',['p=' num2str(P_TLE_R_N(i),1)], 'Position' , [CC_TickVec(i),m_CC_TLE_R_Vec(i)],'color' ,'b');
%         text('String','*', 'Position' , [CC_TickVec(i)-0.15,m_CC_TLE_R_Vec(i)],'color' ,'b','fontsize',24,'fontweight','b');
%     end
%     if H_TLE_L_N(i)    
%         text('String',['p=' num2str(P_TLE_L_N(i),1)], 'Position' , [CC_TickVec(i)-0.25,m_CC_TLE_L_Vec(i)],'color' ,'r');
%         text('String','*', 'Position' , [CC_TickVec(i)-0.35,m_CC_TLE_L_Vec(i)],'color' ,'r','fontsize',24,'fontweight','b');
%     end
%     if H_BI_TLE_N(i)
%         text('String',['p=' num2str(P_BI_TLE_N(i),1)], 'Position' , [CC_TickVec(i)+0.5,m_CC_BI_TLE_Vec(i)] ,'color',[0.5,0,0.5]);
%         text('String','*', 'Position' , [CC_TickVec(i)+0.4,m_CC_BI_TLE_Vec(i)],'Color',[0.5,0,0.5],'fontsize',24,'fontweight','b');
%     end
%     
% end
% 
% 
% 
% legend('U-TLE','R TLE','L TLE','Bi-TLE','Control');

% for i=2:length(CC_TickVec)
%     plot([CC_TickVec(i)-1.5 CC_TickVec(i)-1.5],[0.35 0.8] ,':');
% end

side_BTLE= repmat ('B',[size(BI_TLE_Vector_Cg,1)/9,1]);
side_N=repmat ('N',[size(Normal_Vector_Cg,1)/9,1]);

pval=[];
dev=[];


format long;

%Bd_TLE  Bd_TLE_R  Bd_TLE_L Bd_BI_TLE Bd_Normal
Ge=[Ge_TLE_R; Ge_TLE_L; Ge_BI_TLE; Ge_Normal];
Rb=[Rb_TLE_R; Rb_TLE_L; Rb_BI_TLE; Rb_Normal];
Am=[Am_TLE_R; Am_TLE_L; Am_BI_TLE; Am_Normal];
Pm=[Pm_TLE_R; Pm_TLE_L; Pm_BI_TLE; Pm_Normal];
Bd=[Bd_TLE_R; Bd_TLE_L; Bd_BI_TLE; Bd_Normal];
Is=[Is_TLE_R; Is_TLE_L; Is_BI_TLE; Is_Normal];
Sp=[Sp_TLE_R; Sp_TLE_L; Sp_BI_TLE; Sp_Normal];


CC=[CC_TLE_R; CC_TLE_L; CC_BI_TLE; CC_Normal];
CC_R=[CC_R_TLE_R; CC_R_TLE_L; CC_R_BI_TLE; CC_R_Normal];
CC_L=[CC_L_TLE_R; CC_L_TLE_L; CC_L_BI_TLE; CC_L_Normal];


Cg=[Cg_TLE_R; Cg_TLE_L; Cg_BI_TLE; Cg_Normal];
Cg_L=[Cg_L_TLE_R; Cg_L_TLE_L; Cg_L_BI_TLE; Cg_L_Normal];
Cg_R=[Cg_R_TLE_R; Cg_R_TLE_L; Cg_R_BI_TLE; Cg_R_Normal];
Cg_P=[Cg_P_TLE_R; Cg_P_TLE_L; Cg_P_BI_TLE; Cg_P_Normal];
Cg_S=[Cg_S_TLE_R; Cg_S_TLE_L; Cg_S_BI_TLE; Cg_S_Normal];
Cg_A=[Cg_A_TLE_R; Cg_A_TLE_L; Cg_A_BI_TLE; Cg_A_Normal];
Cg_PL=[Cg_PL_TLE_R; Cg_PL_TLE_L; Cg_PL_BI_TLE; Cg_PL_Normal];
Cg_PR=[Cg_PR_TLE_R; Cg_PR_TLE_L; Cg_PR_BI_TLE; Cg_PR_Normal];
Cg_SL=[Cg_SL_TLE_R; Cg_SL_TLE_L; Cg_SL_BI_TLE; Cg_SL_Normal];
Cg_SR=[Cg_SR_TLE_R; Cg_SR_TLE_L; Cg_SR_BI_TLE; Cg_SR_Normal];
Cg_AL=[Cg_AL_TLE_R; Cg_AL_TLE_L; Cg_AL_BI_TLE; Cg_AL_Normal];
Cg_AR=[Cg_AR_TLE_R; Cg_AR_TLE_L; Cg_AR_BI_TLE; Cg_AR_Normal];

Fx_Ant_TLE_R(isnan(Fx_Ant_TLE_R))=nanmean(Fx_Ant_TLE_R);

Fx=[Fx_TLE_R; Fx_TLE_L; Fx_BI_TLE; Fx_Normal];
Fx_Ant=[Fx_Ant_TLE_R; Fx_Ant_TLE_L; Fx_Ant_BI_TLE; Fx_Ant_Normal];
Fx_L=[Fx_L_TLE_R; Fx_L_TLE_L; Fx_L_BI_TLE; Fx_L_Normal];
Fx_R=[Fx_R_TLE_R; Fx_R_TLE_L; Fx_R_BI_TLE; Fx_R_Normal];


% Features_Mat=[Ge Rb Am Pm Bd Is Sp CC Cg_PL Cg_PR Cg_SL Cg_SR Cg_AL Cg_AR Cg_P Cg_S Cg_A Cg_L Cg_R Cg Fx_Ant Fx_L Fx_R Fx ];
% yticks={'Ge   ', 'Rb   ', 'Am   ', 'Pm   ', 'Bd   ', 'Is   ', 'Sp   ', 'CC   ', 'Cg_PL', 'Cg_PR', 'Cg_SL', 'Cg_SR', 'Cg_AL', 'Cg_AR' ,'Cg_P ', 'Cg_S ', 'Cg_A ', 'Cg_L ', 'Cg_R ', 'Cg   ', 'Fx_At', 'Fx_L ', 'Fx_R ', 'Fx   ' };
% yticks={'1Ge   ', '2Rb   ', '3Am   ', '4Pm   ', '5Bd   ', '6Is   ', '7Sp   ', '8CC   ', '9Cg_PL', '10Cg_PR', '11Cg_SL', '12Cg_SR', '13Cg_AL', '14Cg_AR' ,'15Cg_P ', '16Cg_S ', '17Cg_A ', '18Cg_L ', '19Cg_R ', '20Cg   ', '21Fx_At', '22Fx_L ', '23Fx_R ', '24Fx   ' };

Features_Mat=[Ge Rb Am Pm Is Sp Cg_PL Cg_PR Cg_SL Cg_SR Cg_AL Cg_AR Fx_Ant Fx_L Fx_R];
Features_Mat_R=Features_Mat(1:12,:);
Features_Mat_L=Features_Mat(13:24,:);
Features_Mat_B=Features_Mat(25:31,:);
Features_Mat_C=Features_Mat(32:end,:);
Features_Mat_U=Features_Mat(1:24,:);
Features_Mat_mTLE=Features_Mat(1:31,:);

m_Features_Mat_R=nanmean(Features_Mat_R);
m_Features_Mat_L=nanmean(Features_Mat_L);
m_Features_Mat_B=nanmean(Features_Mat_B);
m_Features_Mat_C=nanmean(Features_Mat_C);

m_Features_Mat=nanmean(Features_Mat);

se_Features_Mat_R=nanstd(Features_Mat_R)./sqrt(12);
se_Features_Mat_L=nanstd(Features_Mat_L)./sqrt(12);
se_Features_Mat_B=nanstd(Features_Mat_B)./sqrt(7);
se_Features_Mat_C=nanstd(Features_Mat_C)./sqrt(23);

TickVec=[1:3:45];

Fx_L_TLE_L=Fx_L_TLE(find(side_TLE=='L'));
Fx_R_TLE_R=Fx_R_TLE(find(side_TLE=='R'));
Fx_L_TLE_R=Fx_L_TLE(find(side_TLE=='R'));
Fx_R_TLE_L=Fx_R_TLE(find(side_TLE=='L'));

m_Fx_L_TLE_L=mean(Fx_L_TLE_L);
m_Fx_L_TLE_R=mean(Fx_L_TLE_R);
m_Fx_R_TLE_L=mean(Fx_R_TLE_L);
m_Fx_R_TLE_R=mean(Fx_R_TLE_R);

s_Fx_L_TLE_L=std(Fx_L_TLE_L)/sqrt(length(Fx_L_TLE_L));
s_Fx_L_TLE_R=std(Fx_L_TLE_R)/sqrt(length(Fx_L_TLE_R));
s_Fx_R_TLE_L=std(Fx_R_TLE_L)/sqrt(length(Fx_R_TLE_L));
s_Fx_R_TLE_R=std(Fx_R_TLE_R)/sqrt(length(Fx_R_TLE_R));


Fx_TLE_Ipsi=[Fx_L_TLE_L;Fx_R_TLE_R];
Fx_TLE_Contra=[Fx_R_TLE_L;Fx_L_TLE_R];


m_Fx_TLE_Ipsi=mean(Fx_TLE_Ipsi);
m_Fx_TLE_Contra=mean(Fx_TLE_Contra);

s_Fx_TLE_Ipsi=std(Fx_TLE_Ipsi)/sqrt(length(Fx_TLE_Ipsi));
s_Fx_TLE_Contra=std(Fx_TLE_Contra)/sqrt(length(Fx_TLE_Contra));

m_Fx_R_Normal=mean(Fx_R_Normal);
m_Fx_L_Normal=mean(Fx_L_Normal);

s_Fx_R_Normal=std(Fx_R_Normal)/sqrt(length(Fx_R_Normal));
s_Fx_L_Normal=std(Fx_L_Normal)/sqrt(length(Fx_L_Normal));

% mVec=[m_Fx_L_Normal m_Fx_R_Normal m_Fx_TLE_Ipsi m_Fx_TLE_Contra];
% sVec=[s_Fx_L_Normal s_Fx_R_Normal s_Fx_TLE_Ipsi s_Fx_TLE_Contra];

mVec=[m_Fx_L_Normal m_Fx_R_Normal m_Fx_L_TLE_L m_Fx_L_TLE_R m_Fx_R_TLE_L m_Fx_R_TLE_R];
sVec=[s_Fx_L_Normal s_Fx_R_Normal s_Fx_L_TLE_L s_Fx_L_TLE_R s_Fx_R_TLE_L s_Fx_R_TLE_R];

% figure(10);
% TickVec2=1:6;
% 
% errorbar(TickVec2,mVec,sVec,'r.','MarkerSize',8,'LineWidth',3);  %[1:.5:2.5],

figure(1);
hold on; 
 
LW=3;
% barweb(barvalues, errors, width, groupnames, bw_title, bw_xlabel, bw_ylabel, bw_colormap, gridstatus, bw_legend, error_sides, legend_type)
% barweb(my_barvalues, my_errors, 1, [], [], [], [], bone, [], bw_legend, 1, 'axis')
% barweb(m_Features_Mat_L,se_Features_Mat_L,[], [], [], [], [], bone, [], [], 1, 'axis');
bar(TickVec+0.75,m_Features_Mat_C,0.3,'K','EdgeColor','K');
bar(TickVec-0.75,m_Features_Mat_L,0.3,'r','EdgeColor','r');
bar(TickVec+0.25,m_Features_Mat_B,0.3,'m','EdgeColor','m');
bar(TickVec-0.25,m_Features_Mat_R,0.3,'b','EdgeColor','b');



% set(hArray(2),'LineWidth',2,'EdgeColor','red')

errorbar(TickVec-0.75,m_Features_Mat_L,zeros(size(se_Features_Mat_L)),se_Features_Mat_L,'.r','MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],
errorbar(TickVec-0.25,m_Features_Mat_R,zeros(size(se_Features_Mat_R)),se_Features_Mat_R,'b.','MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],
errorbar(TickVec+0.25,m_Features_Mat_B,zeros(size(se_Features_Mat_B)),se_Features_Mat_B,'.m','MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],
errorbar(TickVec+0.75,m_Features_Mat_C,zeros(size(se_Features_Mat_C)),se_Features_Mat_C,'K.','MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],

h=legend('Control','L-TLE','Bi-TLE','R-TLE');
set(h,'Orientation','vertical','fontsize',20,'fontweight','b','LineWidth',2);


% errorbar(TickVec(1:6)-0.75,m_Features_Mat_L(1:6),se_Features_Mat_L(1:6),'r','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(1:6)-0.25,m_Features_Mat_R(1:6),se_Features_Mat_R(1:6),'b','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(1:6)+0.25,m_Features_Mat_B(1:6),se_Features_Mat_B(1:6),'Color',[1,0,1],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(1:6)+1,m_Features_Mat_C(1:6),se_Features_Mat_C(1:6),'Color',[0,1,0.75],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% 
% errorbar(TickVec(7:12)-0.75,m_Features_Mat_L(7:12),se_Features_Mat_L(7:12),'r','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(7:12)-0.25,m_Features_Mat_R(7:12),se_Features_Mat_R(7:12),'b','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(7:12)+0.25,m_Features_Mat_B(7:12),se_Features_Mat_B(7:12),'Color',[1,0,1],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(7:12)+1,m_Features_Mat_C(7:12),se_Features_Mat_C(7:12),'Color',[0,1,0.75],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% 
% errorbar(TickVec(13:15)-0.75,m_Features_Mat_L(13:15),se_Features_Mat_L(13:15),'r','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(13:15)-0.25,m_Features_Mat_R(13:15),se_Features_Mat_R(13:15),'b','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(13:15)+0.25,m_Features_Mat_B(13:15),se_Features_Mat_B(13:15),'Color',[1,0,1],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(13:15)+1,m_Features_Mat_C(13:15),se_Features_Mat_C(13:15),'Color',[0,1,0.75],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],


LIMS=[0.2 0.8];
ylim(LIMS);
xlim([-1 46]);

for i=2:length(TickVec)
    plot([TickVec(i)-1.5 TickVec(i)-1.5],LIMS ,':K');
end
plot([TickVec(7)-1.5 TickVec(7)-1.5],LIMS,'K','LineWidth',2 );
plot([TickVec(13)-1.5 TickVec(13)-1.5],LIMS,'K','LineWidth',2 );

set(gca,'XTick',TickVec+0.25,'fontsize',20,'fontweight','b');
ticks={'CC-Ge ', 'CC-Rb ', 'CC-Am ', 'CC-Pm ', 'CC-Is ', 'CC-Sp ',  'Cg-PL ', 'Cg-PR ', 'Cg-SL ', 'Cg-SR ', 'Cg-AL ', 'Cg-AR ' , 'Fx-AB ', 'Fx-LC ', 'Fx-RC ' };
set(gca,'XTickLabel',ticks);
 
pause;

%  XTickLabel = get(gca,'XTickLabel'); 
% xticklabel_rotate90(XTickLabel);
xticklabel_rotate([],90,[],'Fontsize',20,'fontweight','b');
yticklabel_rotate([],90,'Fontsize',20,'fontweight','b');


ylabel([index ],'fontsize',20,'fontweight','b','color','K');

% xticklabel_rotate(TickVec,45,ticks,'fontweight','b','fontsize',12);
 
  
 
% Rotate legend

% Features_Mat=[Ge Bd Sp Cg_PL Cg_PR Cg_SL Cg_SR Cg_AL Cg_AR Fx_Ant Fx_L Fx_R];
% yticks={'Ge   ', 'Bd   ', 'Sp   ',  'Cg_PL', 'Cg_PR', 'Cg_SL', 'Cg_SR', 'Cg_AL', 'Cg_AR' , 'Fx_At', 'Fx_L ', 'Fx_R ' };

n_structures=size(Features_Mat,2);
n_subjects=size(Features_Mat,1);

figure;

% EntireStr_P_Vals=[];
%  %----------------------------------mTLE_L-----------------------------------------
% Features_Mat_L=Features_Mat(13:24,:);
% Features_Vec_L=Features_Mat_L(:);
% Epilepsy_Factor_Mat_L=[1*ones(length(Ge_TLE_L),15)];   
% Epilepsy_Factor_Vec_L=Epilepsy_Factor_Mat_L(:);
% Structure_Factor_Mat_L=[repmat(1:1:15,length(Ge_TLE_L),1)];
% Structure_Factor_Vec_L=Structure_Factor_Mat_L(:);
% [p,t,stats] = anovan(Features_Vec_L,{Structure_Factor_Vec_L,Epilepsy_Factor_Vec_L},'model','full');
% [p,t,stats] = anovan(Features_Vec_L,{Structure_Factor_Vec_L},'model','full');
% % [p,stats] = anova_rm(Features_Mat_L );
% % Perform a multiple comparison of the group means.
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% P_Vals_L=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
%  
% Features_Mat_L=Features_Mat(13:24,1:6);
% Features_Vec_L=Features_Mat_L(:);
% Epilepsy_Factor_Mat_L=[1*ones(length(Ge_TLE_L),6)];   
% Epilepsy_Factor_Vec_L=Epilepsy_Factor_Mat_L(:);
% Structure_Factor_Mat_L=[repmat(1:1:6,length(Ge_TLE_L),1)];
% Structure_Factor_Vec_L=Structure_Factor_Mat_L(:);
% [p,t,stats] = anovan(Features_Vec_L,{Structure_Factor_Vec_L},'model','full');
% 
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
% 
% %----------------------------------mTLE_R-----------------------------------------
% Features_Mat_R=Features_Mat(1:12,:);
% Features_Vec_R=Features_Mat_R(:);
% Epilepsy_Factor_Mat_R=[1*ones(length(Ge_TLE_R),15)];   
% Epilepsy_Factor_Vec_R=Epilepsy_Factor_Mat_R(:);
% Structure_Factor_Mat_R=[repmat(1:1:15,length(Ge_TLE_R),1)];
% Structure_Factor_Vec_R=Structure_Factor_Mat_R(:);
% [p,t,stats] = anovan(Features_Vec_R,{Structure_Factor_Vec_R,Epilepsy_Factor_Vec_R},'model','full');
% [p,t,stats] = anovan(Features_Vec_R,{Structure_Factor_Vec_R},'model','full');
% 
% % Perform a multiple comparison of the group means.
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% 
% P_Vals_R=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
%      
% Features_Mat_R=Features_Mat(1:12,1:6);
% Features_Vec_R=Features_Mat_R(:);
% Epilepsy_Factor_Mat_R=[1*ones(length(Ge_TLE_R),6)];   
% Epilepsy_Factor_Vec_R=Epilepsy_Factor_Mat_R(:);
% Structure_Factor_Mat_R=[repmat(1:1:6,length(Ge_TLE_R),1)];
% Structure_Factor_Vec_R=Structure_Factor_Mat_R(:);
% [p,t,stats] = anovan(Features_Vec_R,{Structure_Factor_Vec_R},'model','full');
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
% 
% %----------------------------------mTLE_U-----------------------------------------
% Features_Mat_U=Features_Mat(1:24,:);
% Features_Vec_U=Features_Mat_U(:);
% Epilepsy_Factor_Mat_U=[1*ones(length(Ge_TLE),15)];   
% Epilepsy_Factor_Vec_U=Epilepsy_Factor_Mat_U(:);
% Structure_Factor_Mat_U=[repmat(1:1:15,length(Ge_TLE),1)];
% Structure_Factor_Vec_U=Structure_Factor_Mat_U(:);
% [p,t,stats] = anovan(Features_Vec_U,{Structure_Factor_Vec_U,Epilepsy_Factor_Vec_U},'model','full');
% [p,t,stats] = anovan(Features_Vec_U,{Structure_Factor_Vec_U},'model','full');
% 
% % Perform a multiple comparison of the group means.
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% 
% P_Vals_U=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
%  
% Features_Mat_U=Features_Mat(1:24,1:6);
% Features_Vec_U=Features_Mat_U(:);
% Epilepsy_Factor_Mat_U=[1*ones(24,6)];   
% Epilepsy_Factor_Vec_U=Epilepsy_Factor_Mat_U(:);
% Structure_Factor_Mat_U=[repmat(1:1:6,24,1)];
% Structure_Factor_Vec_U=Structure_Factor_Mat_U(:);
% [p,t,stats] = anovan(Features_Vec_U,{Structure_Factor_Vec_U},'model','full');
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
%  %----------------------------------mTLE_B-----------------------------------------
% Features_Mat_B=Features_Mat(25:31,:);
% Features_Vec_B=Features_Mat_B(:);
% Epilepsy_Factor_Mat_B=[1*ones(length(Ge_BI_TLE),15)];   
% Epilepsy_Factor_Vec_B=Epilepsy_Factor_Mat_B(:);
% Structure_Factor_Mat_B=[repmat(1:1:15,length(Ge_BI_TLE),1)];
% Structure_Factor_Vec_B=Structure_Factor_Mat_B(:);
% [p,t,stats] = anovan(Features_Vec_B,{Structure_Factor_Vec_B,Epilepsy_Factor_Vec_B},'model','full');
% [p,t,stats] = anovan(Features_Vec_B,{Structure_Factor_Vec_B},'model','full');
% 
% % Perform a multiple comparison of the group means.
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% 
% P_Vals_B=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
% Features_Mat_B=Features_Mat(25:31,1:6);
% Features_Vec_B=Features_Mat_B(:);
% Epilepsy_Factor_Mat_B=[1*ones(7,6)];   
% Epilepsy_Factor_Vec_B=Epilepsy_Factor_Mat_B(:);
% Structure_Factor_Mat_B=[repmat(1:1:6,7,1)];
% Structure_Factor_Vec_B=Structure_Factor_Mat_B(:);
% [p,t,stats] = anovan(Features_Vec_B,{Structure_Factor_Vec_B},'model','full');
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
%        
%  %----------------------------------mTLE-----------------------------------------
% Features_Mat_mTLE=Features_Mat(1:length([Ge_TLE; Ge_BI_TLE]),:);
% Features_Vec_mTLE=Features_Mat_mTLE(:);
% Epilepsy_Factor_Mat_mTLE=[1*ones(length([Ge_TLE; Ge_BI_TLE]),15)];   
% Epilepsy_Factor_Vec_mTLE=Epilepsy_Factor_Mat_mTLE(:);
% Structure_Factor_Mat_mTLE=[repmat(1:1:15,length([Ge_TLE; Ge_BI_TLE]),1)];
% Structure_Factor_Vec_mTLE=Structure_Factor_Mat_mTLE(:);
% [p,t,stats] = anovan(Features_Vec_mTLE,{Structure_Factor_Vec_mTLE,Epilepsy_Factor_Vec_mTLE},'model','full');
% [p,t,stats] = anovan(Features_Vec_mTLE,{Structure_Factor_Vec_mTLE},'model','full');
% 
% % Perform a multiple comparison of the group means.
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% 
% P_Vals_mTLE=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
%   
% Features_Mat_mTLE=Features_Mat(1:length([Ge_TLE; Ge_BI_TLE]),1:6);
% Features_Vec_mTLE=Features_Mat_mTLE(:);
% Epilepsy_Factor_Mat_mTLE=[1*ones(length([Ge_TLE; Ge_BI_TLE]),6)];   
% Epilepsy_Factor_Vec_mTLE=Epilepsy_Factor_Mat_mTLE(:);
% Structure_Factor_Mat_mTLE=[repmat(1:1:6,length([Ge_TLE; Ge_BI_TLE]),1)];
% Structure_Factor_Vec_mTLE=Structure_Factor_Mat_mTLE(:);
% [p,t,stats] = anovan(Features_Vec_mTLE,{Structure_Factor_Vec_mTLE},'model','full');
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
%  %----------------------------------Control-----------------------------------------
% Features_Mat_C=Features_Mat(32:end,:);
% Features_Vec_C=Features_Mat_C(:);
% Epilepsy_Factor_Mat_C=[1*ones(length(Ge_Normal),15)];   
% Epilepsy_Factor_Vec_C=Epilepsy_Factor_Mat_C(:);
% Structure_Factor_Mat_C=[repmat(1:1:15,length(Ge_Normal),1)];
% Structure_Factor_Vec_C=Structure_Factor_Mat_C(:);
% [p,t,stats] = anovan(Features_Vec_C,{Structure_Factor_Vec_C,Epilepsy_Factor_Vec_C},'model','full');
% [p,t,stats] = anovan(Features_Vec_C,{Structure_Factor_Vec_C},'model','full');
% 
% % Perform a multiple comparison of the group means.
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% 
% P_Vals_C=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
%         
% Features_Mat_C=Features_Mat(32:end,1:6);
% Features_Vec_C=Features_Mat_C(:);
% Epilepsy_Factor_Mat_C=[1*ones(length(Ge_Normal),6)];   
% Epilepsy_Factor_Vec_C=Epilepsy_Factor_Mat_C(:);
% Structure_Factor_Mat_C=[repmat(1:1:6,length(Ge_Normal),1)];
% Structure_Factor_Vec_C=Structure_Factor_Mat_C(:);
% [p,t,stats] = anovan(Features_Vec_C,{Structure_Factor_Vec_C},'model','full');
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
% 
% %---------------------------All
% 
% Epilepsy_Factor_Mat=[1*ones(length(Ge_TLE_R),n_structures); 2*ones(length(Ge_TLE_L),n_structures); 3*ones(length(Ge_BI_TLE),n_structures); 4*ones(length(Ge_Normal),n_structures)];
% Epilepsy_Factor_Vec=Epilepsy_Factor_Mat(:);
% Structure_Factor_Mat=[repmat(1:1:n_structures,length(Ge),1)];
% Structure_Factor_Vec=Structure_Factor_Mat(:);
% Features_Vec=Features_Mat(:);
% % [p,t,stats] = anovan(Features_Vec,{Structure_Factor_Vec,Epilepsy_Factor_Vec},'model','full');
% 
% 
% Subject_Mat=repmat([1:n_subjects]',[1 n_structures]);
% Subject_Vec=Subject_Mat(:);
% FACTNAMES={'Structures','mTLE Types','Subjects' } ;
% 
% % stats = rm_anova2(Features_Vec,Subject_Vec, Structure_Factor_Vec,Epilepsy_Factor_Vec, FACTNAMES);
% [p, table] = anova_rm({Features_Mat(1:12,:) Features_Mat(13:24,:) Features_Mat(25:31,:) Features_Mat(32:end,:)} );
% 
% 
% % Perform a multiple comparison of the group means.
% [p,t,stats] = anovan(Features_Vec,{Structure_Factor_Vec},'model','full');
% 
% [c,m,h,nms] = multcompare(stats);
% % [c,m,h,nms] = multcompare(stats,'ctype','lsd');   %t-test
% 
% 
% P_Vals_All=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==2 & c(:,2)==3);find(c(:,1)==3 & c(:,2)==4);find(c(:,1)==4 & c(:,2)==5);find(c(:,1)==5 & c(:,2)==6);...
%           find(c(:,1)==7 & c(:,2)==8)   ;find(c(:,1)==9 & c(:,2)==10)   ;find(c(:,1)==11 & c(:,2)==12);...
%           find(c(:,1)==7 & c(:,2)==9)   ;   find(c(:,1)==9 & c(:,2)==11); find(c(:,1)==8 & c(:,2)==10)   ;find(c(:,1)==10 & c(:,2)==12);...
%           find(c(:,1)==13 & c(:,2)==14)   ; find(c(:,1)==13 & c(:,2)==15)   ;find(c(:,1)==14 & c(:,2)==15)   ;],end);
% 
% Features_Mat_All=Features_Mat(:,1:6);
% Features_Vec_All=Features_Mat_All(:);
% 
% Epilepsy_Factor_Mat=[1*ones(length(Ge_TLE_R),6); 2*ones(length(Ge_TLE_L),6); 3*ones(length(Ge_BI_TLE),6); 4*ones(length(Ge_Normal),6)];
% Epilepsy_Factor_Vec=Epilepsy_Factor_Mat(:);
% Structure_Factor_Mat=[repmat(1:1:6,length(Ge),1)];
% Structure_Factor_Vec=Structure_Factor_Mat(:);
% Features_Vec=Features_Mat(:);
% 
% [p,t,stats] = anovan(Features_Vec_All,{Structure_Factor_Vec},'model','full');
% EntireStr_P_Vals=[EntireStr_P_Vals;p];
% 
% 
% EntireStr_P_Vals
% %---------------------------------------------------------------------------
% TAble_2=[ P_Vals_L P_Vals_R P_Vals_U P_Vals_B P_Vals_mTLE P_Vals_C P_Vals_All]
% 
% TAble_2= [  0.880	0.236	0.118	1.000	0.158	0.313	0.062
%             1.000	1.000	1.000	1.000	1.000	1.000	1.000
%             1.000	1.000	1.000	1.000	1.000	1.000	1.000
%             0.770	0.955	0.558	0.342	0.199	0.999	0.294
%             0.000	0.000	0.000	0.020	0.000	0.000	0.000
%             0.977	1.000	1.000	1.000	1.000	1.000	1.000
%             1.000	1.000	1.000	1.000	1.000	0.437	0.975
%             1.000	1.000	1.000	1.000	1.000	0.041	0.994
%             0.739	0.936	0.499	0.054	0.092	0.000	0.000
%             
%             0.030	0.656	0.022	0.009	0.001	0.000	0.000
%             1.000	0.989	0.999	0.688	0.949	0.000	0.162
%             0.362	0.598	0.102	0.068	0.011	0.000	0.000
%             0.000	0.560	0.000	0.009	0.000	0.000	0.000
%             0.000	0.082	0.000	0.007	0.000	0.000	0.000
%             0.920	1.000	0.942	1.000	0.969	1.000	0.999 ];


% Features_Mat=[Ge Rb Am Pm Is Sp Cg_PL Cg_PR Cg_SL Cg_SR Cg_AL Cg_AR Fx_Ant Fx_L Fx_R];
% % % % Features_Mat_R=Features_Mat(1:12,:);
% % % % Features_Mat_L=Features_Mat(13:24,:);
% % % % Features_Mat_U=Features_Mat(1:24,:);
% % % % Features_Mat_B=Features_Mat(25:31,:);
% % % % Features_Mat_mTLE=Features_Mat(1:31,:);
% % % % Features_Mat_C=Features_Mat(32:end,:);

PVALS_Table2=[];


%Table 2 Statistics in Entire Structures
%---------------CC---------------

p_L_CC=anova_rm(Features_Mat_L(:,1:6));   
p_R_CC=anova_rm(Features_Mat_R(:,1:6));   
p_U_CC=anova_rm(Features_Mat_U(:,1:6));   
p_B_CC=anova_rm(Features_Mat_B(:,1:6));   
p_mTLE_CC=anova_rm(Features_Mat_mTLE(:,1:6));   
p_C_CC=anova_rm(Features_Mat_C(:,1:6));   
p_All_CC=anova_rm(Features_Mat(:,1:6)); 
p_CC_Table2=[ p_L_CC(1) p_R_CC(1)  p_U_CC(1) p_B_CC(1) p_mTLE_CC(1)  p_C_CC(1) p_All_CC(1)];


%---------------Cg---------------

p_L_Cg=anova_rm(Features_Mat_L(:,7:12));   
p_R_Cg=anova_rm(Features_Mat_R(:,7:12));   
p_U_Cg=anova_rm(Features_Mat_U(:,7:12));   
p_B_Cg=anova_rm(Features_Mat_B(:,7:12));   
p_mTLE_Cg=anova_rm(Features_Mat_mTLE(:,7:12));   
p_C_Cg=anova_rm(Features_Mat_C(:,7:12));   
p_All_Cg=anova_rm(Features_Mat(:,7:12)); 
p_Cg_Table2=[ p_L_Cg(1) p_R_Cg(1)  p_U_Cg(1) p_B_Cg(1) p_mTLE_Cg(1)  p_C_Cg(1) p_All_Cg(1)];

%---------------Fx---------------

p_L_Fx=anova_rm(Features_Mat_L(:,13:15));   
p_R_Fx=anova_rm(Features_Mat_R(:,13:15));   
p_U_Fx=anova_rm(Features_Mat_U(:,13:15));   
p_B_Fx=anova_rm(Features_Mat_B(:,13:15));   
p_mTLE_Fx=anova_rm(Features_Mat_mTLE(:,13:15));   
p_C_Fx=anova_rm(Features_Mat_C(:,13:15));   
p_All_Fx=anova_rm(Features_Mat(:,13:15)); 
p_Fx_Table2=[ p_L_Fx(1) p_R_Fx(1)  p_U_Fx(1) p_B_Fx(1) p_mTLE_Fx(1)  p_C_Fx(1) p_All_Fx(1)];

%----------------------------------------------------------------------------


PVALS_Vec=[];
[h p]=ttest(Features_Mat_L(:,1), Features_Mat_L(:,2));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,2), Features_Mat_L(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,3), Features_Mat_L(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,4), Features_Mat_L(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,5), Features_Mat_L(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,7), Features_Mat_L(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,9), Features_Mat_L(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,11), Features_Mat_L(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,7), Features_Mat_L(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,9), Features_Mat_L(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,8), Features_Mat_L(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,10), Features_Mat_L(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,13), Features_Mat_L(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,13), Features_Mat_L(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_L(:,14), Features_Mat_L(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];


PVALS_Vec=[];
[h p]=ttest(Features_Mat_R(:,1), Features_Mat_R(:,2));PVALS_Vec=[PVALS_Vec;p];  %[mean(Features_Mat_R(:,1)) mean(Features_Mat_R(:,2)) PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,2), Features_Mat_R(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,3), Features_Mat_R(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,4), Features_Mat_R(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,5), Features_Mat_R(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,7), Features_Mat_R(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,9), Features_Mat_R(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,11), Features_Mat_R(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,7), Features_Mat_R(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,9), Features_Mat_R(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,8), Features_Mat_R(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,10), Features_Mat_R(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,13), Features_Mat_R(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,13), Features_Mat_R(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_R(:,14), Features_Mat_R(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];

PVALS_Vec=[];
[h p]=ttest(Features_Mat_U(:,1), Features_Mat_U(:,2));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,2), Features_Mat_U(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,3), Features_Mat_U(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,4), Features_Mat_U(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,5), Features_Mat_U(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,7), Features_Mat_U(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,9), Features_Mat_U(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,11), Features_Mat_U(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,7), Features_Mat_U(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,9), Features_Mat_U(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,8), Features_Mat_U(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,10), Features_Mat_U(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,13), Features_Mat_U(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,13), Features_Mat_U(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_U(:,14), Features_Mat_U(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];

PVALS_Vec=[];
[h p]=ttest(Features_Mat_B(:,1), Features_Mat_B(:,2));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,2), Features_Mat_B(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,3), Features_Mat_B(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,4), Features_Mat_B(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,5), Features_Mat_B(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,7), Features_Mat_B(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,9), Features_Mat_B(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,11), Features_Mat_B(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,7), Features_Mat_B(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,9), Features_Mat_B(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,8), Features_Mat_B(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,10), Features_Mat_B(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,13), Features_Mat_B(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,13), Features_Mat_B(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_B(:,14), Features_Mat_B(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];

PVALS_Vec=[];
[h p]=ttest(Features_Mat_mTLE(:,1), Features_Mat_mTLE(:,2));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,2), Features_Mat_mTLE(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,3), Features_Mat_mTLE(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,4), Features_Mat_mTLE(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,5), Features_Mat_mTLE(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,7), Features_Mat_mTLE(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,9), Features_Mat_mTLE(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,11), Features_Mat_mTLE(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,7), Features_Mat_mTLE(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,9), Features_Mat_mTLE(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,8), Features_Mat_mTLE(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,10), Features_Mat_mTLE(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,13), Features_Mat_mTLE(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,13), Features_Mat_mTLE(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_mTLE(:,14), Features_Mat_mTLE(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];

PVALS_Vec=[];
[h p]=ttest(Features_Mat_C(:,1), Features_Mat_C(:,2));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,2), Features_Mat_C(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,3), Features_Mat_C(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,4), Features_Mat_C(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,5), Features_Mat_C(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,7), Features_Mat_C(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,9), Features_Mat_C(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,11), Features_Mat_C(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,7), Features_Mat_C(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,9), Features_Mat_C(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,8), Features_Mat_C(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,10), Features_Mat_C(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,13), Features_Mat_C(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,13), Features_Mat_C(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat_C(:,14), Features_Mat_C(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];

PVALS_Vec=[];
[h p]=ttest(Features_Mat(:,1), Features_Mat(:,2));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,2), Features_Mat(:,3));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,3), Features_Mat(:,4));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,4), Features_Mat(:,5));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,5), Features_Mat(:,6));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,7), Features_Mat(:,8));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,9), Features_Mat(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,11), Features_Mat(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,7), Features_Mat(:,9));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,9), Features_Mat(:,11));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,8), Features_Mat(:,10));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,10), Features_Mat(:,12));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,13), Features_Mat(:,14));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,13), Features_Mat(:,15));PVALS_Vec=[PVALS_Vec;p];
[h p]=ttest(Features_Mat(:,14), Features_Mat(:,15));PVALS_Vec=[PVALS_Vec;p];
PVALS_Table2=[PVALS_Table2 PVALS_Vec];

PVALS_Table2=[ p_CC_Table2; PVALS_Table2(1:5,:); p_Cg_Table2; PVALS_Table2(6:12,:);p_Fx_Table2; PVALS_Table2(13:15,:)];

%   Just for the confirmation of equality f paired MRANOVA with paired t-test --------------------

PVALS_Table2_MRANOVA=[];
PVALS_MRANOVA_Vec=[];
p=anova_rm([Features_Mat(:,1), Features_Mat(:,2)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,2), Features_Mat(:,3)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,3), Features_Mat(:,4)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,4), Features_Mat(:,5)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,5), Features_Mat(:,6)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,7), Features_Mat(:,8)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,9), Features_Mat(:,10)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,11), Features_Mat(:,12)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,7), Features_Mat(:,9)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,9), Features_Mat(:,11)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,8), Features_Mat(:,10)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,10), Features_Mat(:,12)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,13), Features_Mat(:,14)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,13), Features_Mat(:,15)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
p=anova_rm([Features_Mat(:,14), Features_Mat(:,15)],'off');PVALS_MRANOVA_Vec=[PVALS_MRANOVA_Vec;p(1)];
PVALS_Table2_MRANOVA=[PVALS_Table2_MRANOVA PVALS_MRANOVA_Vec];

%   Just for the confirmation of equality with t-test --------------------

Epilepsy_Factor_Mat=[1*ones(length(Ge_TLE_R),n_structures); 2*ones(length(Ge_TLE_L),n_structures); 3*ones(length(Ge_BI_TLE),n_structures); 4*ones(length(Ge_Normal),n_structures)];
% Epilepsy_Factor_Vec=Epilepsy_Factor_Mat(:);
% Structure_Factor_Mat=[repmat(1:1:n_structures,length(Ge),1)];
% Structure_Factor_Vec=Structure_Factor_Mat(:);
% Features_Vec=Features_Mat(:);
% % [p,t,stats] = anovan(Features_Vec,{Structure_Factor_Vec,Epilepsy_Factor_Vec},'model','full');

PVALS_Table1a=[];
for ii=1:n_structures
    Features_Vec=Features_Mat(:,ii);
    Epilepsy_Factor_Vec=Epilepsy_Factor_Mat(:,ii);
    [p,t,stats] = anovan(Features_Vec,{Epilepsy_Factor_Vec},'model','full');
    OverallPVal(ii)=p;
    [c,m,h,nms] = multcompare(stats);
    PVALS_Table1a=[PVALS_Table1a c(:,end)];
end


% 
% PVALS_Table1a=[ 0.002	0.050	0.000	0.939	0.063	0.040
%                 0.001	0.001	0.000	0.887	0.080	0.614
%                 0.009	0.001	0.000	0.547	0.055	0.900
%                 0.030	0.000	0.000	0.120	0.012	0.999
%                 0.05	0.003	0.000	0.360	0.001	0.407
%                 0.000	0.010	0.000	0.805	0.156	0.040
%                 0.05	0.582	0.05	0.758	0.932	0.934
%                 0.000	0.124	0.008	0.151	0.066	0.993
%                 0.048	0.043	0.000	0.946	0.392	0.893
%                 0.005	0.017	0.000	1.000	0.966	0.988
%                 0.757	0.698	0.010	0.995	0.148	0.434
%                 0.019	0.165	0.028	0.956	0.932	1.000
%                 0.161	0.716	0.011	0.847	0.800	0.362
%                 0.730	0.296	0.000	0.810	0.016	0.394
%                 1.000	0.130	0.000	0.130	0.000	0.605 ];
% 
% OverallPVal = [ 0.000000197370347
%                        0.000000114321980
%                        0.000000774147157
%                        0.000000241678433
%                        0.000000085605405
%                        0.000000010397841
%                        0.052556205697846
%                        0.000083068968040
%                        0.000595034787819
%                        0.000342086833848
%                        0.011498768959964
%                        0.015342203845783
%                        0.007987481513050
%                        0.000424421002041
%                        0.000026060179840];    

B_correted_Alpha=0.0083;

figure(1); 
for i=1:size(PVALS_Table1a,2)
    
        if PVALS_Table1a(1,i) <= B_correted_Alpha % R vs. L
             text('String','*', 'Position' , [TickVec(i)-0.25-0.25,m_Features_Mat_R(i)-0.01],'Color',[1,0,0],'fontsize',20,'fontweight','b');%+se_Features_Mat_R(i)
             text('String','*', 'Position' , [TickVec(i)-0.75-0.25,m_Features_Mat_L(i)+se_Features_Mat_L(i)+0.005],'Color',[0,0,1],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1a(2,i) <= B_correted_Alpha % R vs. B
             text('String','*', 'Position' , [TickVec(i)-0.25-0.25,m_Features_Mat_R(i)-0.03],'Color',[1,0,1],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.25-0.5,m_Features_Mat_B(i)+se_Features_Mat_B(i)+0.005],'Color',[0,0,1],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1a(3,i) <= B_correted_Alpha % R vs. C
            text('String','*', 'Position' , [TickVec(i)-0.25-0.25,m_Features_Mat_R(i)-0.02],'Color',[0,0,0],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.75-0.25,m_Features_Mat_C(i)+se_Features_Mat_C(i)+0.005],'Color',[0,0,1],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1a(4,i) <= B_correted_Alpha % L vs. B
             text('String','*', 'Position' , [TickVec(i)-0.75-0.25,m_Features_Mat_L(i)+se_Features_Mat_L(i)+0.015],'Color',[1,0,1],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.25-0.5,m_Features_Mat_B(i)+se_Features_Mat_B(i)+0.015],'Color',[1,0,0],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1a(5,i) <= B_correted_Alpha % L vs. C
             text('String','*', 'Position' , [TickVec(i)-0.75-0.25,m_Features_Mat_L(i)+se_Features_Mat_L(i)+0.025],'Color',[0,0,0],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.75-0.25,m_Features_Mat_C(i)+se_Features_Mat_C(i)+0.015],'Color',[1,0,0],'fontsize',20,'fontweight','b');
        end
   
         if PVALS_Table1a(6,i) <= B_correted_Alpha % B vs. C
             text('String','*', 'Position' , [TickVec(i)+0.25-0.5,m_Features_Mat_B(i)+se_Features_Mat_B(i)+0.025],'Color',[0,0,0],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.75-0.25,m_Features_Mat_C(i)+se_Features_Mat_C(i)+0.025],'Color',[1,0,1],'fontsize',20,'fontweight','b');
        end
       
end
PVALS_Table1a=PVALS_Table1a([5 3 6 4 2 1],:);

PVALS_Table1a=[PVALS_Table1a' OverallPVal'];

% Features_Mat=[Ge Rb Am Pm Is Sp Cg_PL Cg_PR Cg_SL Cg_SR Cg_AL Cg_AR Fx_Ant Fx_L Fx_R];
% Epilepsy_Factor_Mat=[R; L; B; N];


%-----------------Volumetry and FLAIR Analysis

load F:\MatlabCodes\FLAIR_Vol_TLE_AllPatientsVector;  %Old_KOST_FLAIR_Vol_TLE_AllPatientsVector  % %FLAIR_Parameters T1_Parameters FLAIR_Patients T1_Patients
FLAIR_TLE_Vector =  FLAIR_Parameters;
T1_TLE_Vector =  T1_Parameters;

load F:\MatlabCodes\FLAIR_Vol_BI_TLE_AllPatientsVector;  %Old_KOST_FLAIR_Vol_TLE_AllPatientsVector  % %FLAIR_Parameters T1_Parameters FLAIR_Patients T1_Patients
FLAIR_BI_TLE_Vector =  FLAIR_Parameters;
T1_BI_TLE_Vector =  T1_Parameters;

index2='Volumes and FLAIR intensities in Hippocampus'
Normal_FLAIR_Vector=[ 215.2415225	212.4483846	27.19240856	30.43781307
                221.7283856	222.1640401	26.35170557	28.53155751
                233.7584877	231.7373068	24.02240599	29.25203086
                202.6590909	206.4204334	25.67265345	26.11768625
                257.1649066	259.2364747	24.87202242	25.65697323
                238.2516383	237.2609254	22.30320672	25.94384319
                176.8522409	177.8194338	38.83198155	37.25296772
                241.531781	242.9429429	25.79537826	27.85692303
                271.1476395	261.1059942	27.72019941	28.81550463
                262.1345725	266.0966876	30.61160594	30.18710408
                269.7424354	271.2076974	27.08729678	29.19429339
                257.8852978	259.091651	28.94761892	29.24236596
                238.2082683	237.572856	25.16781137	27.03756453
                236.5225363	234.4371166	28.47299522	31.16160984
                272.9515997	271.2084328	26.25972561	24.38644212
                207.2527473	210.1793215	24.46558114	25.51700165
                219.4791289	221.5623902	25.85105489	26.84608841
                203.8467202	211.3891304	26.49401731	26.30724411
                213.5	    211.441358	25.9390007	27.95765611
                207.1628319	210.9468947	20.62001828	23.92480463
                242.5501497	245.3097072	27.08273688	30.03936633
                262.4707561	257.7305808	33.36953032	37.29242526
                185.1492939	193.6807747	28.61804503	29.00056866 ]; %
%                 258.4340029	260.0750536	30.54534751	28.74525674
%                 212.0535117	212.1983887	23.97514132	26.15813259 ];

% Volumetry--------------------------------------------------



HippVol1=[
                3135.199707	2926.593018	1576845.625
                2406.90625	2525.23877	1409338.125
                2450.823486	2427.64502	1248273
                2761.903564	2833.878906	1484567.125
                2278.814453	2184.880371	1242612.625
                3404.80249	3453.599365	1494975.5
                2541.097656	2428.864746	1475903.25
                2783.862061	2911.953857	1254351.875
                2181.220703	2461.802734	1287992.5
                2476.441895	2115.344971	1321796.5
                2494.740723	2774.102783	1391851.75
                2885.115723	2850.957764	1301886.25
                2402.026611	2189.76001	1393165.625
                2323.951416	2400.806641	1306369.375
                2210.498779	2414.22583	1396489.875
                2100.705811	2287.35376	1373909.125
                2040.929565	2068.987793	1697854.625
                2781.422363	2585.014893	1577181.125
                2270.274902	2366.648926	1249685.75
                2833.878906	2782.642334	1821925.5
                2469.122314	2323.951416	1427125.875
                2505.719971	2587.45459	1282949.375
                2703.347412	2658.210205	1816525]; 
            
%                 2521.578857	2393.487061	1217864
%                 2051.309326	2244.634277	1615894.625 ];
%           
    
%  HippVol2=[
%             17950	18875	8142288
%             14708	15547	7030678
%             15284	16241	8187513
%             14632	16210	7343335
%             17678	18195	8611413
%             17809	18153	7729481
%             20984	22100	9985421
%             19091	20577	7460180
%             17392	18954	7998599
%             17829	18351	9211893
%             15221	15979	7023353
%             16087	15445	7985713
%             21903	22333	9145694
%             17517	18176	7982634
%             18730	19029	8519822
%             18927	18946	9258784
%             13996	14726	7724888
%             20454	21074	9876544
%             17963	17843	8653444
%             17661	17820	8593211
%           ];

       
Normal_Vol_Vector=[HippVol1]; %;HippVol2];  

Normal_Vector=[Normal_FLAIR_Vector Normal_Vol_Vector];
BI_TLE_Vector=[FLAIR_BI_TLE_Vector T1_BI_TLE_Vector];


% side=repmat('N',size(T1_Parameters,1),1);

  IND=1;
  
FLAIR_M_L_TLE=FLAIR_TLE_Vector(:,1);
FLAIR_M_R_TLE=FLAIR_TLE_Vector(:,2);
FLAIR_S_L_TLE=FLAIR_TLE_Vector(:,3)*10;
FLAIR_S_R_TLE=FLAIR_TLE_Vector(:,4)*10;

FLAIR_L_TLE=FLAIR_M_L_TLE .* FLAIR_S_L_TLE/1000;
FLAIR_R_TLE=FLAIR_M_R_TLE .* FLAIR_S_R_TLE/1000;

Vol_L_TLE=T1_TLE_Vector(:,1)/10;
Vol_R_TLE=T1_TLE_Vector(:,2)/10;

%--------R- mTLE--------------
FLAIR_M_L_TLE_R=FLAIR_M_L_TLE(side_TLE=='R');
FLAIR_M_R_TLE_R=FLAIR_M_R_TLE(side_TLE=='R');
FLAIR_S_L_TLE_R=FLAIR_S_L_TLE(side_TLE=='R');
FLAIR_S_R_TLE_R=FLAIR_S_R_TLE(side_TLE=='R');
FLAIR_L_TLE_R=FLAIR_L_TLE(side_TLE=='R');
FLAIR_R_TLE_R=FLAIR_R_TLE(side_TLE=='R');
Vol_L_TLE_R=Vol_L_TLE(side_TLE=='R');
Vol_R_TLE_R=Vol_R_TLE(side_TLE=='R');

%--------L- mTLE--------------
FLAIR_M_L_TLE_L=FLAIR_M_L_TLE(side_TLE=='L');
FLAIR_M_R_TLE_L=FLAIR_M_R_TLE(side_TLE=='L');
FLAIR_S_L_TLE_L=FLAIR_S_L_TLE(side_TLE=='L');
FLAIR_S_R_TLE_L=FLAIR_S_R_TLE(side_TLE=='L');
FLAIR_L_TLE_L=FLAIR_L_TLE(side_TLE=='L');
FLAIR_R_TLE_L=FLAIR_R_TLE(side_TLE=='L');
Vol_L_TLE_L=Vol_L_TLE(side_TLE=='L');
Vol_R_TLE_L=Vol_R_TLE(side_TLE=='L');

% %-------Normal---------------------------------
FLAIR_M_L_Normal=Normal_Vector(:,1);
FLAIR_M_R_Normal=Normal_Vector(:,2);
FLAIR_S_L_Normal=Normal_Vector(:,3)*10;
FLAIR_S_R_Normal=Normal_Vector(:,4)*10;

FLAIR_L_Normal=FLAIR_M_L_Normal .* FLAIR_S_L_Normal/1000;
FLAIR_R_Normal=FLAIR_M_R_Normal .* FLAIR_S_R_Normal/1000;

Vol_L_Normal=Normal_Vector(:,5)/10;
Vol_R_Normal=Normal_Vector(:,6)/10;

% %-------BL---------------------------------
% 
% 
FLAIR_M_L_TLE_BI=BI_TLE_Vector(:,1);
FLAIR_M_R_TLE_BI=BI_TLE_Vector(:,2);
FLAIR_S_L_TLE_BI=BI_TLE_Vector(:,3)*10;
FLAIR_S_R_TLE_BI=BI_TLE_Vector(:,4)*10;

% FLAIR_L_BI_TLE=FLAIR_M_L_BI_TLE .* FLAIR_S_L_BI_TLE/1000;
% FLAIR_R_BI_TLE=FLAIR_M_R_BI_TLE .* FLAIR_S_R_BI_TLE/1000;

[FLAIR_M_L_TLE_BI.*FLAIR_S_L_TLE_BI FLAIR_M_R_TLE_BI.*FLAIR_S_R_TLE_BI]

Vol_L_TLE_BI=BI_TLE_Vector(:,5)/10;
Vol_R_TLE_BI=BI_TLE_Vector(:,6)/10;

%------------------------------------------


Lat_FLAIR_TLE=repmat('R', size(FLAIR_M_L_Normal));
Lat_FLAIR_TLE(FLAIR_R_TLE < FLAIR_L_TLE)='L';


Lat_Vol_TLE=repmat('R', size(Vol_L_TLE));
Lat_Vol_TLE(Vol_R_TLE > Vol_L_TLE)='L';

FLAIR_M_L_Hipp=[FLAIR_M_L_TLE_R; FLAIR_M_L_TLE_L; FLAIR_M_L_TLE_BI; FLAIR_M_L_Normal];
FLAIR_M_R_Hipp=[FLAIR_M_R_TLE_R; FLAIR_M_R_TLE_L; FLAIR_M_R_TLE_BI; FLAIR_M_R_Normal];
FLAIR_S_L_Hipp=[FLAIR_S_L_TLE_R; FLAIR_S_L_TLE_L; FLAIR_S_L_TLE_BI; FLAIR_S_L_Normal];
FLAIR_S_R_Hipp=[FLAIR_S_R_TLE_R; FLAIR_S_R_TLE_L; FLAIR_S_R_TLE_BI; FLAIR_S_R_Normal];
Vol_L_Hipp=[Vol_L_TLE_R; Vol_L_TLE_L; Vol_L_TLE_BI; Vol_L_Normal];
Vol_R_Hipp=[Vol_R_TLE_R; Vol_R_TLE_L; Vol_R_TLE_BI; Vol_R_Normal];

Features_Mat=[FLAIR_M_L_Hipp FLAIR_M_R_Hipp FLAIR_S_L_Hipp FLAIR_S_R_Hipp Vol_L_Hipp Vol_R_Hipp];
Features_Mat_R=Features_Mat(1:12,:);
Features_Mat_L=Features_Mat(13:24,:);
Features_Mat_B=Features_Mat(25:31,:);
Features_Mat_C=Features_Mat(32:end,:);

m_Features_Mat_R=nanmean(Features_Mat_R);
m_Features_Mat_L=nanmean(Features_Mat_L);
m_Features_Mat_B=nanmean(Features_Mat_B);
m_Features_Mat_C=nanmean(Features_Mat_C);

m_Features_Mat=nanmean(Features_Mat);

se_Features_Mat_R=nanstd(Features_Mat_R)./sqrt(12);
se_Features_Mat_L=nanstd(Features_Mat_L)./sqrt(12);
se_Features_Mat_B=nanstd(Features_Mat_B)./sqrt(7);
se_Features_Mat_C=nanstd(Features_Mat_C)./sqrt(23);

TickVec=[1:3:18];

figure(2);
hold on; 
 

bar(TickVec-0.75,m_Features_Mat_L+2,0.25,'r','EdgeColor','r');  %+0
bar(TickVec-0.25,m_Features_Mat_R+2,0.25,'b','EdgeColor','b');
bar(TickVec+0.25,m_Features_Mat_B+2,0.25,'m','EdgeColor','m');
bar(TickVec+0.75,m_Features_Mat_C+2,0.25,'K','EdgeColor','K');

errorbar(TickVec-0.75,m_Features_Mat_L,zeros(size(se_Features_Mat_L)),se_Features_Mat_L,'r.','MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],
errorbar(TickVec-0.25,m_Features_Mat_R,zeros(size(se_Features_Mat_R)),se_Features_Mat_R,'b.','MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],
errorbar(TickVec+0.25,m_Features_Mat_B,zeros(size(se_Features_Mat_B)),se_Features_Mat_B,'.','Color',[1,0,1],'MarkerSize',8,'LineWidth',LW);  %[1:.5:2.5],
errorbar(TickVec+0.75,m_Features_Mat_C,zeros(size(se_Features_Mat_C)),se_Features_Mat_C,'.','Color',[0,0,0],'MarkerSize',8,'LineWidth',3);  %[1:.5:2.5],

% errorbar(TickVec(1:2)-0.75,m_Features_Mat_L(1:2),se_Features_Mat_L(1:2),'r','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(1:2)-0.25,m_Features_Mat_R(1:2),se_Features_Mat_R(1:2),'b','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(1:2)+0.25,m_Features_Mat_B(1:2),se_Features_Mat_B(1:2),'Color',[1,0,1],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(1:2)+1,m_Features_Mat_C(1:2),se_Features_Mat_C(1:2),'Color',[0,1,0.75],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% 
% errorbar(TickVec(3:4)-0.75,m_Features_Mat_L(3:4),se_Features_Mat_L(3:4),'r','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(3:4)-0.25,m_Features_Mat_R(3:4),se_Features_Mat_R(3:4),'b','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(3:4)+0.25,m_Features_Mat_B(3:4),se_Features_Mat_B(3:4),'Color',[1,0,1],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(3:4)+1,m_Features_Mat_C(3:4),se_Features_Mat_C(3:4),'Color',[0,1,0.75],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% 
% errorbar(TickVec(5:6)-0.75,m_Features_Mat_L(5:6),se_Features_Mat_L(5:6),'r','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(5:6)-0.25,m_Features_Mat_R(5:6),se_Features_Mat_R(5:6),'b','MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(5:6)+0.25,m_Features_Mat_B(5:6),se_Features_Mat_B(5:6),'Color',[1,0,1],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],
% errorbar(TickVec(5:6)+1,m_Features_Mat_C(5:6),se_Features_Mat_C(5:6),'Color',[0,1,0.75],'MarkerSize',8,'LineWidth',2);  %[1:.5:2.5],


LIMS=[50 500];
ylim(LIMS);
xlim([-1 19]);

for i=2:length(TickVec)
    plot([TickVec(i)-1.5 TickVec(i)-1.5],LIMS ,':K');
end
plot([TickVec(3)-1.5 TickVec(3)-1.5],LIMS,'K','LineWidth',2 );
plot([TickVec(5)-1.5 TickVec(5)-1.5],LIMS,'K','LineWidth',2 );

set(gca,'XTick',TickVec+0.25,'fontsize',14,'fontweight','b');
% ticks={'mean FLAIR ','mean FLAIR ','10*Std FLAIR ','10*Std FLAIR', 'Volume/10 ', 'Volume/10 '};    
% XLABS=['Left Hippocampus    ','Right Hippocampus    ','Left Hippocampus    ','Right Hippocampus    ', 'Left Hippocampus    ','Right Hippocampus    '];
% xlabel (XLABS);    
% ticks={['Left Hippocampus ';'Mean FLAIR       '],['Right Hippocampus';'Mean FLAIR       '],['Left Hippocampus ';'Std FLAIR x 10   '],['Right Hippocampus';'Std FLAIR x 10   '] ,['Left Hippocampus ';'Volume/10        '],['Right Hippocampus';'Volume/10        '] };
ticks={'LH','RH','LH','RH','LH','RH'};
set(gca,'XTickLabel',ticks,'Fontsize',20,'fontweight','b');

  text('String','Mean FLAIR', 'Position' , [1.5,490],'Color',[0,0,0],'fontsize',20,'fontweight','b');
  text('String','Std FLAIR x 10', 'Position' , [7,490],'Color',[0,0,0],'fontsize',20,'fontweight','b');
  text('String','Volume/10', 'Position' , [13.5,490],'Color',[0,0,0],'fontsize',20,'fontweight','b');


%   pause;
%  XTickLabel = get(gca,'XTickLabel'); 
% xticklabel_rotate90(XTickLabel);
% xticklabel_rotate([],90,[],'Fontsize',14,'fontweight','b');
ylabel('Hippocampal Measurements','fontsize',20,'fontweight','b','color','K');
yticklabel_rotate([],90,'Fontsize',20,'fontweight','b');



% xticklabel_rotate(TickVec,45,ticks,'fontweight','b','fontsize',12);
 
  
 
% h=legend('L-TLE','R-TLE','Bi-TLE','Control','Orientation','vertical');

h=legend('L-TLE','R-TLE','Bi-TLE','Control');
set(h,'Orientation','vertical','fontsize',20,'fontweight','b','LineWidth',2);

% Rotate legend

% Features_Mat=[Ge Bd Sp Cg_PL Cg_PR Cg_SL Cg_SR Cg_AL Cg_AR Fx_Ant Fx_L Fx_R];
% yticks={'Ge   ', 'Bd   ', 'Sp   ',  'Cg_PL', 'Cg_PR', 'Cg_SL', 'Cg_SR', 'Cg_AL', 'Cg_AR' , 'Fx_At', 'Fx_L ', 'Fx_R ' };

n_structures=size(Features_Mat,2);

figure;
 %----------------------------------mTLE_L-----------------------------------------
Features_Mat_L=Features_Mat(13:24,:);
Features_Vec_L=Features_Mat_L(:);
Epilepsy_Factor_Mat_L=[1*ones(length(Ge_TLE_L),n_structures)];   
Epilepsy_Factor_Vec_L=Epilepsy_Factor_Mat_L(:);
Structure_Factor_Mat_L=[repmat(1:1:n_structures,length(Ge_TLE_L),1)];
Structure_Factor_Vec_L=Structure_Factor_Mat_L(:);
[p,t,stats] = anovan(Features_Vec_L,{Structure_Factor_Vec_L,Epilepsy_Factor_Vec_L},'model','full');
[p,t,stats] = anovan(Features_Vec_L,{Structure_Factor_Vec_L},'model','full');
% [p,t,stats] = rmanova(Features_Vec_L,{Structure_Factor_Vec_L},'model','full');
% Perform a multiple comparison of the group means.
c=[];
stat=[];

[c,m,h,nms] = multcompare(stats);

P_Vals_L=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);
 
%----------------------------------mTLE_R-----------------------------------------
Features_Mat_R=Features_Mat(1:12,:);
Features_Vec_R=Features_Mat_R(:);
Epilepsy_Factor_Mat_R=[1*ones(length(Ge_TLE_R),n_structures)];   
Epilepsy_Factor_Vec_R=Epilepsy_Factor_Mat_R(:);
Structure_Factor_Mat_R=[repmat(1:1:n_structures,length(Ge_TLE_R),1)];
Structure_Factor_Vec_R=Structure_Factor_Mat_R(:);
[p,t,stats] = anovan(Features_Vec_R,{Structure_Factor_Vec_R,Epilepsy_Factor_Vec_R},'model','full');
[p,t,stats] = anovan(Features_Vec_R,{Structure_Factor_Vec_R},'model','full');
% Perform a multiple comparison of the group means.
[c,m,h,nms] = multcompare(stats);

P_Vals_R=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);
     
        
%----------------------------------mTLE_U-----------------------------------------
Features_Mat_U=Features_Mat(1:24,:);
Features_Vec_U=Features_Mat_U(:);
Epilepsy_Factor_Mat_U=[1*ones(length(Ge_TLE),n_structures)];   
Epilepsy_Factor_Vec_U=Epilepsy_Factor_Mat_U(:);
Structure_Factor_Mat_U=[repmat(1:1:n_structures,length(Ge_TLE),1)];
Structure_Factor_Vec_U=Structure_Factor_Mat_U(:);
[p,t,stats] = anovan(Features_Vec_U,{Structure_Factor_Vec_U,Epilepsy_Factor_Vec_U},'model','full');
[p,t,stats] = anovan(Features_Vec_U,{Structure_Factor_Vec_U},'model','full');
% Perform a multiple comparison of the group means.
[c,m,h,nms] = multcompare(stats);

P_Vals_U=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);
         
 %----------------------------------mTLE_B-----------------------------------------
Features_Mat_B=Features_Mat(25:31,:);
Features_Vec_B=Features_Mat_B(:);
Epilepsy_Factor_Mat_B=[1*ones(length(Ge_BI_TLE),n_structures)];   
Epilepsy_Factor_Vec_B=Epilepsy_Factor_Mat_B(:);
Structure_Factor_Mat_B=[repmat(1:1:n_structures,length(Ge_BI_TLE),1)];
Structure_Factor_Vec_B=Structure_Factor_Mat_B(:);
[p,t,stats] = anovan(Features_Vec_B,{Structure_Factor_Vec_B,Epilepsy_Factor_Vec_B},'model','full');
[p,t,stats] = anovan(Features_Vec_B,{Structure_Factor_Vec_B},'model','full');
% Perform a multiple comparison of the group means.
[c,m,h,nms] = multcompare(stats);

P_Vals_B=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);
      
 %----------------------------------mTLE-----------------------------------------
Features_Mat_mTLE=Features_Mat(1:length([Ge_TLE; Ge_BI_TLE]),:);
Features_Vec_mTLE=Features_Mat_mTLE(:);
Epilepsy_Factor_Mat_mTLE=[1*ones(length([Ge_TLE; Ge_BI_TLE]),n_structures)];   
Epilepsy_Factor_Vec_mTLE=Epilepsy_Factor_Mat_mTLE(:);
Structure_Factor_Mat_mTLE=[repmat(1:1:n_structures,length([Ge_TLE; Ge_BI_TLE]),1)];
Structure_Factor_Vec_mTLE=Structure_Factor_Mat_mTLE(:);
[p,t,stats] = anovan(Features_Vec_mTLE,{Structure_Factor_Vec_mTLE,Epilepsy_Factor_Vec_mTLE},'model','full');
[p,t,stats] = anovan(Features_Vec_mTLE,{Structure_Factor_Vec_mTLE},'model','full');
% Perform a multiple comparison of the group means.
[c,m,h,nms] = multcompare(stats);

P_Vals_mTLE=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);
        
 %----------------------------------Control-----------------------------------------
Features_Mat_C=Features_Mat(32:end,:);
Features_Vec_C=Features_Mat_C(:);
Epilepsy_Factor_Mat_C=[1*ones(length(Ge_Normal),n_structures)];   
Epilepsy_Factor_Vec_C=Epilepsy_Factor_Mat_C(:);
Structure_Factor_Mat_C=[repmat(1:1:n_structures,length(Ge_Normal),1)];
Structure_Factor_Vec_C=Structure_Factor_Mat_C(:);
[p,t,stats] = anovan(Features_Vec_C,{Structure_Factor_Vec_C,Epilepsy_Factor_Vec_C},'model','full');
[p,t,stats] = anovan(Features_Vec_C,{Structure_Factor_Vec_C},'model','full');
% Perform a multiple comparison of the group means.
[c,m,h,nms] = multcompare(stats);

P_Vals_C=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);
     

%---------------------------All-------------------

Epilepsy_Factor_Mat=[1*ones(length(Ge_TLE_R),n_structures); 2*ones(length(Ge_TLE_L),n_structures); 3*ones(length(Ge_BI_TLE),n_structures); 4*ones(length(Ge_Normal),n_structures)];
Epilepsy_Factor_Vec=Epilepsy_Factor_Mat(:);
Structure_Factor_Mat=[repmat(1:1:n_structures,length(Ge),1)];
Structure_Factor_Vec=Structure_Factor_Mat(:);
Features_Vec=Features_Mat(:);
[p,t,stats] = anovan(Features_Vec,{Structure_Factor_Vec,Epilepsy_Factor_Vec},'model','full');

   

% Perform a multiple comparison of the group means.
[p,t,stats] = anovan(Features_Vec,{Structure_Factor_Vec},'model','full');

[c,m,h,nms] = multcompare(stats);

P_Vals_All=c([find(c(:,1)==1 & c(:,2)==2);find(c(:,1)==1 & c(:,2)==3);...
          find(c(:,1)==2 & c(:,2)==3)   ;find(c(:,1)==2 & c(:,2)==4)  ;...
          find(c(:,1)==5 & c(:,2)==6)   ;],end);


%----------------------------------All-----------------------------------------
TAble_1=[ P_Vals_L P_Vals_R P_Vals_U P_Vals_B P_Vals_mTLE P_Vals_C P_Vals_All];

% TAble_1=[0.880	0.236	0.118	1.000	0.158	0.313	0.062
%             1.000	1.000	1.000	1.000	1.000	1.000	1.000
%             1.000	1.000	1.000	1.000	1.000	1.000	1.000
%             0.770	0.955	0.558	0.342	0.199	0.999	0.294
%             0.000	0.000	0.000	0.020	0.000	0.000	0.000
%             0.977	1.000	1.000	1.000	1.000	1.000	1.000
%             1.000	1.000	1.000	1.000	1.000	0.437	0.975
%             1.000	1.000	1.000	1.000	1.000	0.041	0.994
%             0.739	0.936	0.499	0.054	0.092	0.000	0.000
%             0.030	0.656	0.022	0.009	0.001	0.000	0.000
%             1.000	0.989	0.999	0.688	0.949	0.000	0.162
%             0.362	0.598	0.102	0.068	0.011	0.000	0.000
%             0.000	0.560	0.000	0.009	0.000	0.000	0.000
%             0.000	0.082	0.000	0.007	0.000	0.000	0.000
%             0.920	1.000	0.942	1.000	0.969	1.000	0.999 ];

PVALS_Table1b=[];
OverallPVal=[];
for ii=1:n_structures
    Features_Vec=Features_Mat(:,ii);
    Epilepsy_Factor_Vec=Epilepsy_Factor_Mat(:,ii);
    [p,t,stats] = anovan(Features_Vec,{Epilepsy_Factor_Vec},'model','full');
    OverallPVal(ii)=p;
    [c,m,h,nms] = multcompare(stats);
    PVALS_Table1b=[PVALS_Table1b c(:,end)];
end

OverallPVal'

% PVALS=[ 0.002	0.050	0.000	0.939	0.063	0.040
%         0.001	0.001	0.000	0.887	0.080	0.614
%         0.009	0.001	0.000	0.547	0.055	0.900
%         0.030	0.000	0.000	0.120	0.012	0.999
%         0.05	0.003	0.000	0.360	0.001	0.407
%         0.000	0.010	0.000	0.805	0.156	0.040
%         0.05	0.582	0.05	0.758	0.932	0.934
%         0.000	0.124	0.008	0.151	0.066	0.993
%         0.048	0.043	0.000	0.946	0.392	0.893
%         0.005	0.017	0.000	1.000	0.966	0.988
%         0.757	0.698	0.010	0.995	0.148	0.434
%         0.019	0.165	0.028	0.956	0.932	1.000
%         0.161	0.716	0.011	0.847	0.800	0.362
%         0.730	0.296	0.000	0.810	0.016	0.394
%         1.000	0.130	0.000	0.130	0.000	0.605 ]';
    

figure(2); 
% for i=1:size(PVALS_Table1b,2)
%     
%         if PVALS_Table1b(1,i) <= B_correted_Alpha % R vs. L
%              text('String','*', 'Position' , [TickVec(i)-0.25+0.1,m_Features_Mat_R(i)],'Color',[1,0,0],'fontsize',20,'fontweight','b');
%              text('String','*', 'Position' , [TickVec(i)-0.75+0.1,m_Features_Mat_L(i)],'Color',[0,0,1],'fontsize',20,'fontweight','b');
%         end
%         if PVALS_Table1b(2,i) <= B_correted_Alpha % R vs. B
%              text('String','*', 'Position' , [TickVec(i)-0.25+0.1,m_Features_Mat_R(i)-10],'Color',[1,0,1],'fontsize',20,'fontweight','b');
%              text('String','*', 'Position' , [TickVec(i)+0.25+0.1,m_Features_Mat_B(i)-10],'Color',[0,0,1],'fontsize',20,'fontweight','b');
%         end
%         if PVALS_Table1b(3,i) <= B_correted_Alpha % R vs. C
%              text('String','*', 'Position' , [TickVec(i)-0.25+0.1,m_Features_Mat_R(i)-10],'Color',[0,1,0.75],'fontsize',20,'fontweight','b');
%              text('String','*', 'Position' , [TickVec(i)+1+0.1,m_Features_Mat_C(i)],'Color',[0,0,1],'fontsize',20,'fontweight','b');
%         end
%         if PVALS_Table1b(4,i) <= B_correted_Alpha % L vs. B
%              text('String','*', 'Position' , [TickVec(i)-0.75+0.1,m_Features_Mat_L(i)+10],'Color',[1,0,1],'fontsize',20,'fontweight','b');
%              text('String','*', 'Position' , [TickVec(i)+0.25+0.1,m_Features_Mat_B(i)+10],'Color',[1,0,0],'fontsize',20,'fontweight','b');
%         end
%         if PVALS_Table1b(5,i) <= B_correted_Alpha % L vs. C
%              text('String','*', 'Position' , [TickVec(i)-0.75+0.1,m_Features_Mat_L(i)+10],'Color',[0,1,0.75],'fontsize',20,'fontweight','b');
%              text('String','*', 'Position' , [TickVec(i)+1+0.1,m_Features_Mat_C(i)+10],'Color',[1,0,0],'fontsize',20,'fontweight','b');
%         end
%    
%          if PVALS_Table1b(6,i) <= B_correted_Alpha % B vs. C
%              text('String','*', 'Position' , [TickVec(i)+0.25+0.1,m_Features_Mat_B(i)],'Color',[0,1,0.75],'fontsize',20,'fontweight','b');
%              text('String','*', 'Position' , [TickVec(i)+1+0.1,m_Features_Mat_C(i)-10],'Color',[1,0,1],'fontsize',20,'fontweight','b');
%         end
%        
% end


B_correted_Alpha=0.0083;

for i=1:size(PVALS_Table1b,2)
    
        if PVALS_Table1b(1,i) <= B_correted_Alpha % R vs. L
             text('String','*', 'Position' , [TickVec(i)-0.25-0.1,m_Features_Mat_R(i)+se_Features_Mat_R(i)+10],'Color',[1,0,0],'fontsize',20,'fontweight','b');%+se_Features_Mat_R(i)
             text('String','*', 'Position' , [TickVec(i)-0.75-0.25,m_Features_Mat_L(i)+se_Features_Mat_L(i)+10],'Color',[0,0,1],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1b(2,i) <= B_correted_Alpha % R vs. B
             text('String','*', 'Position' , [TickVec(i)-0.25-0.1,m_Features_Mat_R(i)+se_Features_Mat_R(i)+15],'Color',[1,0,1],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.25-0.1,m_Features_Mat_B(i)+se_Features_Mat_B(i)+15],'Color',[0,0,1],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1b(3,i) <= B_correted_Alpha % R vs. C
            text('String','*', 'Position' , [TickVec(i)-0.25-0.1,m_Features_Mat_R(i)+se_Features_Mat_R(i)+5],'Color',[0,0,0],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.75+0.25,m_Features_Mat_C(i)+se_Features_Mat_C(i)+15],'Color',[0,0,1],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1b(4,i) <= B_correted_Alpha % L vs. B
             text('String','*', 'Position' , [TickVec(i)-0.75-0.25,m_Features_Mat_L(i)+se_Features_Mat_L(i)+15],'Color',[1,0,1],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.25-0.1,m_Features_Mat_B(i)+se_Features_Mat_B(i)+10],'Color',[1,0,0],'fontsize',20,'fontweight','b');
        end
        if PVALS_Table1b(5,i) <= B_correted_Alpha % L vs. C
             text('String','*', 'Position' , [TickVec(i)-0.75-0.25,m_Features_Mat_L(i)+se_Features_Mat_L(i)+5],'Color',[0,0,0],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.75+0.25,m_Features_Mat_C(i)+se_Features_Mat_C(i)+10],'Color',[1,0,0],'fontsize',20,'fontweight','b');
        end
   
         if PVALS_Table1b(6,i) <= B_correted_Alpha % B vs. C
             text('String','*', 'Position' , [TickVec(i)+0.25-0.1,m_Features_Mat_B(i)+se_Features_Mat_B(i)+5],'Color',[0,0,0],'fontsize',20,'fontweight','b');
             text('String','*', 'Position' , [TickVec(i)+0.75+0.25,m_Features_Mat_C(i)+se_Features_Mat_C(i)+20],'Color',[1,0,1],'fontsize',20,'fontweight','b');
        end
       
end

%---------------------------------------------------------------
PVALS_Table1b=PVALS_Table1b([5 3 6 4 2 1],:);

PVALS_Table1b=[PVALS_Table1b' OverallPVal'];

% 
% PVALS=[PVALS' OverallPVal'];
% 
% PVALS_Table1=[PVALS_Table1; PVALS];
% 
% PVALS_Table1=PVALS_Table1(:,[5 3 6 4 2 1 7]);

% L mTLE     vs.    Control	R mTLE    vs.    Control	B mTLE    vs.    Control	L mTLE     vs.              B mTLE	R mTLE     vs.              B mTLE	L mTLE    vs.              R mTLE	Overall mTLE Effect (3 df)

%-----------------Classifications----------------


% TR=[FLAIR_M_L_Hipp FLAIR_M_R_Hipp];
% TR=[ FLAIR_S_L_Hipp FLAIR_S_R_Hipp];
% TR= [FLAIR_M_L_Hipp FLAIR_M_R_Hipp  FLAIR_S_L_Hipp FLAIR_S_R_Hipp]; 
% TR=[Vol_L_Hipp Vol_R_Hipp];

TR=[FLAIR_M_L_Hipp FLAIR_M_R_Hipp FLAIR_S_L_Hipp FLAIR_S_R_Hipp Vol_L_Hipp Vol_R_Hipp];
% index='Hippocampal FLAIR Signal and Volume';

% TR=[Ge Rb Am Pm Is Sp CC_L CC_R Cg_P Cg_PL Cg_PR Cg_S Cg_SL Cg_SR Cg_A Cg_AL Cg_AR Fx_L Fx_R];  %(8 9 2) 

% TR=[Ge Rb Am Pm Is Sp CC];   %CC
% TR=[Cg_P Cg_PL Cg_PR Cg_S Cg_SL Cg_SR Cg_A Cg_AL Cg_AR];  %Cg% TR=[Cg_P Cg_S Cg_A Cg_L Cg_R];  %Cg
% TR=[Fx Fx_L Fx_R]; %Fx

% TR=[Ge Rb Am Pm Is Sp CC Cg_P Cg_PL Cg_PR Cg_S Cg_SL Cg_SR Cg_A Cg_AL Cg_AR ];  %CC-Cg 

% TR=[Ge Rb Am Pm Is Sp CC Fx Fx_L Fx_R];  %CC-Fx

% TR=[Cg_P Cg_PL Cg_PR Cg_S Cg_SL Cg_SR Cg_A Cg_AL Cg_AR Fx Fx_L Fx_R];   %Cg-Fx

% TR=[Ge Rb Am Pm Is Sp CC_L CC_R Cg_P Cg_PL Cg_PR Cg_S Cg_SL Cg_SR Cg_A Cg_AL Cg_AR Fx_L Fx_R];    %Complete 

% % % % % TR=[Ge Rb Am Pm Is Sp CC Cg_P Cg_PL Cg_PR Cg_S Cg_SL Cg_SR Cg_A Cg_AL Cg_AR Fx Fx_L Fx_R];    

% TR=[Ge Rb Am Pm Is Sp Cg_AL Cg_AR Cg_SL Cg_SR Cg_PL Cg_PR Fx_Ant Fx_L Fx_R];  % Final

% TR=[Ge Rb Am Pm Is Sp Cg_AL Cg_AR Cg_SL Cg_SR Cg_PL Cg_PR Fx_Ant Fx_L Fx_R];  % Final Cg_AL Cg_AR  

TS=TR;

Pr_all=[];
dev=[];
side_R=repmat('R' , length(Fx_TLE_R),1);
side_L=repmat('L' , length(Fx_TLE_L),1);
side_TLE=[side_R;side_L];

% % % % % % % % --------------------------------------------Feature Selections
% % % % % % % % side=[side_R; side_L; side_BTLE; side_N];
% % % % % % % % side_nom = nominal(side);
% % % % % % % % side_nom_d = double(side_nom);
% % % % % % % % tmp=zeros(size(side_nom_d));
% % % % % % % % tmp(side_nom_d==2)=1;  tmp(side_nom_d==4)=2;  tmp(side_nom_d==1)=3; tmp(side_nom_d==3)=4;
% % % % % % % % side_nom_d=tmp;
% % % % % % % % nInx=find(~isnan(TR(:,1)));
% % % % % % % % [b0,dev0,stats0] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
% % % % % % % % model0 = [b0 stats0.se];       
% % % % % % % % maxdev = chi2inv(.95,1);     
% % % % % % % % opt = statset('display','iter',...
% % % % % % % %               'TolFun',maxdev,...
% % % % % % % %               'TolTypeFun','abs','MaxIter',Inf);
% % % % % % % % X=TR;
% % % % % % % % Y=side_nom_d;
% % % % % % % % inmodel = sequentialfs(@critfun,X,Y,...
% % % % % % % %                        'cv','none',...
% % % % % % % %                        'nullmodel',true,...
% % % % % % % %                        'options',opt,...
% % % % % % % %                        'direction','forward');
% % % % % % % %                  
% % % % % % % % TR=TR(:,inmodel==1);  



TR_Origin=TR;
TS_Orig=TS;

for num=1:8
    try
    switch num
        case 1  % R Vs. L   %100
            
%             TR=[Ge Rb Am Pm Is Sp Cg_P Cg_S Cg_A Fx_L Fx_R]; %100  Cg_PR Cg_PL Cg_SR Cg_SL Cg_AR Cg_AL
%             TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==2)=1;  tmp(side_nom_d==1)=2;  
            side_nom_d=tmp;
            
            lege='R vs. L ';
            
            TR=TR(1:length(side),:);

            TS=TS(1:length(side),:);
            
%  % % % % % % % % % % % % % % % ------------------Prodominance of 5 Bilateral Cases--------------------                       
% % % % % % % % % % % % % % % % %             side_BTLE=['B'; 'R'; 'B'; 'B'; 'L'; 'B'; 'R'; 'B'; 'B'; 'L'; 'R'; 'B'];
% % % % % % % % % % % % % % % % % comment  TS=TS(1:length(side),:);
% % % % % % % % % % % % % % % % %             TS=TS(25:36,:);
            
            nInx=find(~isnan(TR(:,1)));
            [B,dev(:,num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
            [P_all P_l_all P_u_all]=mnrval(B,TS,stats);
             x_axis1_Test=TS*B(2:end,1) + B(1,1);
             
            x_axis1=TR*B(2:end,1) + B(1,1);
                   
            Pr_all(:,2)=1./(1+exp(x_axis1));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1));
              
            stp=(length(x_axis1)-1)./(max(x_axis1) - min(x_axis1));
            x_axis_plot=[min(x_axis1) : stp/10 : max(x_axis1)];
            Pr_R_Plot=exp(x_axis_plot)./(1+exp(x_axis_plot));
            
%             [x_axis_sort x_axis_sort_ind]=sort(x_axis1);
%             Pr_R=Pr_all(:,1);
%             Pr_R_sort = Pr_R (x_axis_sort_ind);
                
            figure(num+30)
            plot(x_axis_plot,Pr_R_Plot,'MarkerSize',12,'LineWidth',2,'color','b')
            hold
%             for kk=1:length(side_nom_d)
%                 if side_nom_d(kk)==1
%                     plot(x_axis1(kk),side_nom_d(kk),'x','MarkerSize',15,'LineWidth',2,'color','r');
%                 elseif side_nom_d(kk)==2
%                     plot(x_axis1(kk),side_nom_d(kk)-2,'o','MarkerSize',12,'LineWidth',2,'color','b');
%                 end
%             end
% %             
% %             plot(x_axis1,Pr_all(:,2),'b.')

% % % % % % % % % % % % % % % %------------------Prodominance of 5 Bilateral Cases--------------------
% % % % % % % % % % % % % % % y_axis1_Test=zeros(size(x_axis1_Test));
% % % % % % % % % % % % % % % y_axis1_Test(find(side_BTLE=='B'))=0.5;
% % % % % % % % % % % % % % % y_axis1_Test(find(side_BTLE=='L'))=0.0;
% % % % % % % % % % % % % % % y_axis1_Test(find(side_BTLE=='R'))=1.0;
% % % % % % % % % % % % % % % plot(x_axis1_Test(find(side_BTLE=='L')),y_axis1_Test(find(side_BTLE=='L')),'o','MarkerSize',15,'LineWidth',2,'color','r');
% % % % % % % % % % % % % % % plot(x_axis1_Test(find(side_BTLE=='R')),y_axis1_Test(find(side_BTLE=='R')),'x','MarkerSize',15,'LineWidth',2,'color','b');
% % % % % % % % % % % % % % % ylabel(['Probability of the Bilateral cases being more Dominant in Right vs. Left, M' num2str(num)],'fontsize',15,'fontweight','b');
% % % % % % % % % % % % % % % legend( 'Right TLE Logistic Fit','Bilateral TLE cases with L > R', 'Bilateral TLE cases with R > L' );
% % % % % % % % % % % % % % % %     plot(x_axis1_Test(find(side_BTLE=='B')),y_axis1_Test(find(side_BTLE=='B')),'x','MarkerSize',15,'LineWidth',2,'color','g');
            plot(x_axis1(side_nom_d==1),side_nom_d((side_nom_d==1)),'x','MarkerSize',15,'LineWidth',2,'color','b');
            plot(x_axis1(side_nom_d==2),side_nom_d((side_nom_d==2))-2,'o','MarkerSize',15,'LineWidth',2,'color','r');
            legend( 'Right TLE Logistic Fit','Data Point Classified as Right', 'Data Point Classified as Left' );
            ylabel(['Probability of the Unilateral cases being Right vs. Left, M' num2str(num)],'fontsize',15,'fontweight','b');
      
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            
            [decidedSide_P, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
                
            nL=length(find(side_nom_d==2));
            nR=length(find(side_nom_d==1));
            nAll=nL+nR;
             P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2)))/nAll;
       case 2     %Unilateral vs. Bilateral  
 
%             TR=[ Ge Rb Am Pm Is Sp CC_L CC_R Cg_P Cg_PR Cg_PL  Cg_S Cg_SR Cg_SL Cg_A Cg_AR Cg_AL Fx_L Fx_R]; % 100%    
%             TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L; side_BTLE];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==2)=1;  tmp(side_nom_d==3)=1;  tmp(side_nom_d==1)=2;  
            side_nom_d=tmp;
            
            lege='Unilateral vs. Bilateral';
            
            TR=TR(1:length(side),:);
            TS=TS(1:length(side),:);
         
            nInx=find(~isnan(TR(:,1)));
            [B,dev(:,num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
            [P_all P_l_all P_u_all]=mnrval(B,TS,stats);
            
            x_axis1=TR*B(2:end,1) + B(1,1);
              Pr_all=[];      
            Pr_all(:,2)=1./(1+exp(x_axis1));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1));
              
            stp=(length(x_axis1)-1)./(max(x_axis1) - min(x_axis1));
            x_axis_plot=[min(x_axis1) : stp/10 : max(x_axis1)];
            Pr_R_Plot=exp(x_axis_plot)./(1+exp(x_axis_plot));
            
%             [x_axis_sort x_axis_sort_ind]=sort(x_axis1);
%             Pr_R=Pr_all(:,1);
%             Pr_R_sort = Pr_R (x_axis_sort_ind);
                
            figure(num+30)
            plot(x_axis_plot,Pr_R_Plot,'MarkerSize',12,'LineWidth',2,'color','b')
            hold
%             for kk=1:length(side_nom_d)
%                 if side_nom_d(kk)==1
%                     plot(x_axis1(kk),side_nom_d(kk),'x','MarkerSize',15,'LineWidth',2,'color','r');
%                
%                     text('String',[Uni_pats(kk,:)], 'Position' , [x_axis1(kk),side_nom_d(kk)-0.3],'color' ,'b');
%                 elseif side_nom_d(kk)==2
%                     text('String',[BI_pats(kk-24,:)], 'Position' , [x_axis1(kk),side_nom_d(kk)-2+0.3],'color' ,'b');
%                     plot(x_axis1(kk),side_nom_d(kk)-2,'o','MarkerSize',12,'LineWidth',2,'color','b');
%                 end
%             end
% %             
% %             plot(x_axis1,Pr_all(:,2),'b.')
%            
            plot(x_axis1(side_nom_d==1),side_nom_d((side_nom_d==1)),'x','MarkerSize',15,'LineWidth',2,'color','b');
            plot(x_axis1(side_nom_d==2),side_nom_d((side_nom_d==2))-2,'o','MarkerSize',15,'LineWidth',2,'color','r');
            ylabel(['Probability of the cases being Unilateral vs. Bilateral, M' num2str(num)],'fontsize',15,'fontweight','b');
            legend( 'Unilateral TLE Logistic Fit','Data Point Classified as Unilateral TLE', 'Data Point Classified as Bilateral TLE' );
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            [decidedSide_P, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
                
            nB=length(find(side_nom_d==2));
            nU=length(find(side_nom_d==1));
            nAll=nU+nB;
            P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2)))/nAll;
        case 5   %  R vs. L. vs BiTLE  100%
   
%             TR=[Ge Rb Am Pm Is Sp Cg_P Cg_S Fx_L Fx_R Cg_PR Cg_PL CC_L CC_R]; % 100%
%             TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L; side_BTLE];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==3)=1;  tmp(side_nom_d==2)=2; tmp(side_nom_d==1)=3;  
            side_nom_d=tmp;
            
            lege='R vs. L vs. BiTLE ';
            
            TR=TR(1:length(side),:);
            TS=TS(1:length(side),:);
            
            %TRAIN------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            
            nInx=find(~isnan(TR(:,1)));
            [B,dev(:,num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
            %     [ P_all(:,:,num) P_l_all(:,:,num) P_u_all(:,:,num)]=mnrval(B,TS,stats);
                        
            x_axis1=TR*B(2:end,1) + B(1,1);
            x_axis2=TR*B(2:end,2) + B(1,2);
             Pr_all=[];
            Pr_all(:,3)=1./(1+exp(x_axis1)+exp(x_axis2));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1)+exp(x_axis2));
            Pr_all(:,2)=exp(x_axis2)./(1+exp(x_axis1)+exp(x_axis2));
            
            
%             figure(111)
%             plot(x_axis1,Pr_all(:,3),'g.')
%             hold
%             plot(x_axis1,Pr_all(:,1),'r.')
%             plot(x_axis1,Pr_all(:,2),'b.')
            
            
            [decidedSide_P_all, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
            [X1,X2] = ndgrid (-25:0.5:25,-25:0.5:25);%(min(x_axis1):1:max(x_axis1),min(x_axis2):1:max(x_axis2));
            
            Z3=1./(1+exp(X1)+exp(X2));
            Z1=exp(X1)./(1+exp(X1)+exp(X2));
            Z2=exp(X2)./(1+exp(X1)+exp(X2));
            
            
            %     figure(num+10)
          figure(num+30)
            
            %             plot3(X1,X2,Z2,'r.');
            mesh(X1,X2,Z1,'FaceLighting','flat ','EdgeColor','b','LineWidth',0.1);
%             plot3(X1,X2,Z1,'r');
            hold
            plot3(x_axis1,x_axis2,Pr_all(:,1),'b*','LineWidth',4);%mesh(Z2);
            %             plot3(X1,X2,Z3,'b.');
            mesh(X1,X2,Z2,'FaceLighting','flat ','EdgeColor','r','LineWidth',0.1);
%             plot3(X1,X2,Z2,'b');
            plot3(x_axis1,x_axis2,Pr_all(:,2),'r*','LineWidth',4);%   mesh(Z3);
            
            
            mesh(X1,X2,Z3,'FaceLighting','flat ','EdgeColor','g','LineWidth',0.1);  %plot3(X1,X2,Z1,'g.');
%             plot3(X1,X2,Z3,'g');
            plot3(x_axis1,x_axis2,Pr_all(:,3),'g*','LineWidth',4);
            xlim([-50 50]); ylim([-50 50]);
            axis([-30 30 -30 30 0 1]);
           
            zlabel(['Probability of the cases being Right TLE, vs. Left TLE, vs. BiTemporal M' num2str(num)],'fontsize',15,'fontweight','b');
            legend( 'Right TLE Logistic Fit','Data Point Classified as Right', 'Left TLE Logistic Fit', 'Data Point Classified as Left', 'Bilateral TLE Logistic Fit', 'Data Point Classified as BiTemporal' );
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            ylabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            nL=length(find(side_nom_d==2));
            nR=length(find(side_nom_d==1));
            nB=length(find(side_nom_d==3));
            nAll=nL+nR+nB;
             P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2))+ length(find(decidedSide_ind(side_nom_d==3)==3)))/nAll;
       
        case 6    %R vs L vs N  %100
             
%             TR=[Ge Rb Am Pm Is Sp CC_L CC_R Cg_PR Cg_PL Cg_P Cg_S Fx_L Fx_R ]; %  Cg_SR Cg_SL Cg_AR Cg_AL    
%             TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L; side_N];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==1)=2;  tmp(side_nom_d==3)=1; tmp(side_nom_d==2)=3;  
            side_nom_d=tmp;
            
            lege='R vs. L vs. Control ';
            
            TR(length(side_TLE)+1 : length(side_TLE)+ length(side_BTLE) ,:)=[];
            TS(length(side_TLE)+1 : length(side_TLE)+ length(side_BTLE) ,:)=[];
            
            %TRAIN------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            
            nInx=find(~isnan(TR(:,1)));
            [B,dev(:,num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
            %     [ P_all(:,:,num) P_l_all(:,:,num) P_u_all(:,:,num)]=mnrval(B,TS,stats);
                        
            x_axis1=TR*B(2:end,1) + B(1,1);
            x_axis2=TR*B(2:end,2) + B(1,2);
            Pr_all=[];
            Pr_all(:,3)=1./(1+exp(x_axis1)+exp(x_axis2));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1)+exp(x_axis2));
            Pr_all(:,2)=exp(x_axis2)./(1+exp(x_axis1)+exp(x_axis2));
            
            
%             figure(111)
%             plot(x_axis1,Pr_all(:,3),'g.')
%             hold
%             plot(x_axis1,Pr_all(:,1),'r.')
%             plot(x_axis1,Pr_all(:,2),'b.')
            
            
            [decidedSide_P_all, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
            %     [X1,X2] = ndgrid(-1.5*max(x_axis1_8):1:1.5*max(x_axis1_8),-1.5*max(x_axis2_8):1:1.5*max(x_axis2_8));
            [X1,X2] = ndgrid (-25:0.5:25,-25:0.5:25);%(min(x_axis1):1:max(x_axis1),min(x_axis2):1:max(x_axis2));
            
            Z3=1./(1+exp(X1)+exp(X2));
            Z1=exp(X1)./(1+exp(X1)+exp(X2));
            Z2=exp(X2)./(1+exp(X1)+exp(X2));
            
            
            %     figure(num+10)
        figure(num+30)
            
            %             plot3(X1,X2,Z2,'r.');
            mesh(X1,X2,Z1,'FaceLighting','flat ','EdgeColor','b','LineWidth',0.1);
%             plot3(X1,X2,Z1,'r');
            hold
            plot3(x_axis1,x_axis2,Pr_all(:,1),'b*','LineWidth',4);%mesh(Z2);
            %             plot3(X1,X2,Z3,'b.');
            mesh(X1,X2,Z2,'FaceLighting','flat ','EdgeColor','r','LineWidth',0.1);
%             plot3(X1,X2,Z2,'b');
            plot3(x_axis1,x_axis2,Pr_all(:,2),'r*','LineWidth',4);%   mesh(Z3);
            
            
            mesh(X1,X2,Z3,'FaceLighting','flat ','EdgeColor','g','LineWidth',0.1);  %plot3(X1,X2,Z1,'g.');
%             plot3(X1,X2,Z3,'g');
            plot3(x_axis1,x_axis2,Pr_all(:,3),'g*','LineWidth',4);
            xlim([-50 50]); ylim([-50 50]);
            axis([-30 30 -30 30 0 1]);
           
            zlabel(['Probability of the cases being Right TLE, vs. Left TLE, vs. Control M' num2str(num)],'fontsize',15,'fontweight','b');
            legend( 'Right TLE Logistic Fit','Data Point Classified as Right', 'Left TLE Logistic Fit', 'Data Point Classified as Left', 'Control Logistic Fit', 'Data Point Classified as Control' );
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            ylabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            
            nL=length(find(side_nom_d==2));
            nR=length(find(side_nom_d==1));
            nB=length(find(side_nom_d==3));
            nAll=nL+nR+nB;
             P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2))+ length(find(decidedSide_ind(side_nom_d==3)==3)))/nAll;
        case 3     %Bilateral vs. Normal   %100
       
%             TR=[ Ge Rb Am Pm Is Sp CC_L CC_R Cg_P Cg_PR Cg_PL  Cg_S Cg_SR Cg_SL Cg_A Cg_AR Cg_AL Fx_L Fx_R]; % % 
%             TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side_TLE=[side_R; side_L];
            side=[side_BTLE; side_N];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
                        
            lege='Bilateral vs. Cortrol ';
            
            TR(1:length(side_TLE),:)=[];
            TS(1:length(side_TLE),:)=[];
         
            nInx=find(~isnan(TR(:,1)));
%             [B,dev(:,num),stats] 
            [B,dev(:,num)]= mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
%             ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
             Pr_all=[];
%              [P_all P_l_all P_u_all]=mnrval(B,TS,stats);
            
            x_axis1=TR*B(2:end,1) + B(1,1);
                   
            Pr_all(:,2)=1./(1+exp(x_axis1));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1));
              
            stp=(length(x_axis1)-1)./(max(x_axis1) - min(x_axis1));
            x_axis_plot=[min(x_axis1) : stp/10 : max(x_axis1)];
            Pr_R_Plot=exp(x_axis_plot)./(1+exp(x_axis_plot));
            
%             [x_axis_sort x_axis_sort_ind]=sort(x_axis1);
%             Pr_R=Pr_all(:,1);
%             Pr_R_sort = Pr_R (x_axis_sort_ind);
                
            figure(num+30)
            plot(x_axis_plot,Pr_R_Plot,'MarkerSize',12,'LineWidth',2,'color','b')
            hold
%             for kk=1:length(side_nom_d)
%                 if side_nom_d(kk)==1
%                     plot(x_axis1(kk),side_nom_d(kk),'x','MarkerSize',15,'LineWidth',2,'color','b');
%                
% %                     text('String',[Uni_pats(kk,:)], 'Position' , [x_axis1(kk),side_nom_d(kk)-0.3],'color' ,'b');
%                 elseif side_nom_d(kk)==2
%                     plot(x_axis1(kk),side_nom_d(kk)-2,'o','MarkerSize',12,'LineWidth',2,'color','r');
%                 end
%             end
%             
            plot(x_axis1(side_nom_d==1),side_nom_d((side_nom_d==1)),'x','MarkerSize',15,'LineWidth',2,'color','b');
            plot(x_axis1(side_nom_d==2),side_nom_d((side_nom_d==2))-2,'o','MarkerSize',15,'LineWidth',2,'color','r');
            ylabel(['Probability of the cases being Bilateral vs. Control, M' num2str(num)],'fontsize',15,'fontweight','b');
%             legend( 'Right Logistic Fit','Data Point Classified as Bilateral', 'Data Point Classified as Control' );
            legend( 'Bilateral TLE Logistic Fit','Data Point Classified as Bilateral TLE', 'Data Point Classified as Control' );
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');

            [decidedSide_P, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
                
            nB=length(find(side_nom_d==2));
            nU=length(find(side_nom_d==1));
            nAll=nU+nB;
            P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2)))/nAll;
    
      case 4   %TLE vs. Cortrol  
            
%             TR=[Ge Rb Am Pm Is Sp Fx_L Fx_R]; %89.83
%             TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L; side_BTLE; side_N];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==1)=1;  tmp(side_nom_d==2)=1;  tmp(side_nom_d==4)=1;  tmp(side_nom_d==3)=2;  
            side_nom_d=tmp;
            
            lege='TLE vs. Cortrol ';
            
                    
            nInx=find(~isnan(TR(:,1)));
            [B,dev(:,num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
             Pr_all=[];
             [P_all P_l_all P_u_all]=mnrval(B,TS,stats);
            
            x_axis1=TR*B(2:end,1) + B(1,1);
                   
            Pr_all(:,2)=1./(1+exp(x_axis1));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1));
              
            stp=(length(x_axis1)-1)./(max(x_axis1) - min(x_axis1));
            x_axis_plot=[min(x_axis1) : stp/10 : max(x_axis1)];
            Pr_R_Plot=exp(x_axis_plot)./(1+exp(x_axis_plot));
            
%             [x_axis_sort x_axis_sort_ind]=sort(x_axis1);
%             Pr_R=Pr_all(:,1);
%             Pr_R_sort = Pr_R (x_axis_sort_ind);
                
            figure(num+30)
            plot(x_axis_plot,Pr_R_Plot,'MarkerSize',12,'LineWidth',2,'color','b')
            hold
%             for kk=1:length(side_nom_d)
%                 if side_nom_d(kk)==1
%                     plot(x_axis1(kk),side_nom_d(kk),'x','MarkerSize',15,'LineWidth',2,'color','r');
%                 elseif side_nom_d(kk)==2
%                     plot(x_axis1(kk),side_nom_d(kk)-2,'o','MarkerSize',12,'LineWidth',2,'color','b');
%                 end
%             end
% %             
% %             plot(x_axis1,Pr_all(:,2),'b.')

            plot(x_axis1(side_nom_d==1),side_nom_d((side_nom_d==1)),'x','MarkerSize',15,'LineWidth',2,'color','b');
            plot(x_axis1(side_nom_d==2),side_nom_d((side_nom_d==2))-2,'o','MarkerSize',15,'LineWidth',2,'color','r');
            ylabel(['Probability of the cases being TLE vs. Control, M' num2str(num)],'fontsize',15,'fontweight','b');
            legend( 'TLE Logistic Fit','Data Point Classified as TLE', 'Data Point Classified as Control' );
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            [decidedSide_P, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
                
            nL=length(find(side_nom_d==2));
            nR=length(find(side_nom_d==1));
            nAll=nL+nR;
             P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2)))/nAll;
        
                            
         case 8  %  R vs. L  vs. B vs. N   %100
            
%        TR=[Rb Am Pm Is Sp CC_L CC_R Cg_PR Cg_P Cg_S Cg_SR Cg_SL Cg_AR Cg_AL Fx_L Fx_R]; %96.61   
         %x Ge Cg_PL Fx
         %- Cg_A
%          TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L; side_BTLE; side_N];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==2)=1;  tmp(side_nom_d==4)=2;  tmp(side_nom_d==1)=3; tmp(side_nom_d==3)=4;
            side_nom_d=tmp;
            lege='R vs. L  vs. B vs. N';
            
            nInx=find(~isnan(TR(:,1)));
            [B,dev(:,num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
            %     [ P_all(:,:,num) P_l_all(:,:,num) P_u_all(:,:,num)]=mnrval(B,TS,stats);


            x_axis1=TR*B(2:end,1) + B(1,1);
            x_axis2=TR*B(2:end,2) + B(1,2);
            x_axis3=TR*B(2:end,3) + B(1,3);

            %     Pr_all(:,3,num)=1./(1+exp(x_axis1)+exp(x_axis2));
            %     Pr_all(:,1,num)=exp(x_axis1)./(1+exp(x_axis1)+exp(x_axis2));
            %     Pr_all(:,2,num)=exp(x_axis2)./(1+exp(x_axis1)+exp(x_axis2));
            %
             Pr_all=[];
             Pr_all(:,4)=1./(1+exp(x_axis1)+exp(x_axis2)+exp(x_axis3));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1)+exp(x_axis2)+exp(x_axis3));
            Pr_all(:,2)=exp(x_axis2)./(1+exp(x_axis1)+exp(x_axis2)+exp(x_axis3));
            Pr_all(:,3)=exp(x_axis3)./(1+exp(x_axis1)+exp(x_axis2)+exp(x_axis3));

          figure(num+30)
            plot(x_axis1,Pr_all(:,4),'g.')
            hold
            plot(x_axis1,Pr_all(:,1),'r.')
            plot(x_axis1,Pr_all(:,2),'K.')
            plot(x_axis1,Pr_all(:,3),'b.')


            [decidedSide_P, decidedSide_ind]=max(Pr_all');

            [side_nom_d decidedSide_ind']
            
            nL=length(find(side_nom_d==1));
            nR=length(find(side_nom_d==2));
            nB=length(find(side_nom_d==3));
            nC=length(find(side_nom_d==4));
            nAll=nL+nR+nB+nC;
            
             P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2))+length(find(decidedSide_ind(side_nom_d==3)==3))+length(find(decidedSide_ind(side_nom_d==4)==4)))/nAll;
        case 7  %Unilateral Vs. Bilateral Vs. Normal
            
%            TR=[Ge Am Pm Is Sp CC CC_L CC_R Cg_P Cg_PR Cg_PL  Cg_S Cg_SR Cg_SL Cg_A Cg_AR Cg_AL Fx_L Fx_R]; %96.61     
%            TR=[Ge Rb Am Pm Is Sp CC_L CC_R Cg_P Cg_PR Cg_PL Cg_SR Cg_S Cg_SL Cg_A Cg_AR Cg_AL Fx_L Fx_R]; 
%            TS=TR;
            TR=TR_Origin;
            TS=TS_Orig;

            side=[side_R; side_L; side_BTLE; side_N];
            side_nom = nominal(side);
            side_nom_d = double(side_nom);
            tmp=zeros(size(side_nom_d));
            tmp(side_nom_d==1)=2;  tmp(side_nom_d==2)=1; tmp(side_nom_d==4)=1; tmp(side_nom_d==3)=3;   
            side_nom_d=tmp;
            
             lege='Unilateral vs. Bilateral vs. Control ';
            
                        
            %TRAIN------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            
            nInx=find(~isnan(TR(:,1)));
            [B,dev(num),stats] = mnrfit(TR(nInx,:),side_nom_d(nInx));   %side_nom_d
            ttmp=stats.p;
            NoDataPoints(num)=length(nInx);
            %     [ P_all(:,:,num) P_l_all(:,:,num) P_u_all(:,:,num)]=mnrval(B,TS,stats);
                        
            x_axis1=TR*B(2:end,1) + B(1,1);
            x_axis2=TR*B(2:end,2) + B(1,2);
             Pr_all=[];
            Pr_all(:,3)=1./(1+exp(x_axis1)+exp(x_axis2));
            Pr_all(:,1)=exp(x_axis1)./(1+exp(x_axis1)+exp(x_axis2));
            Pr_all(:,2)=exp(x_axis2)./(1+exp(x_axis1)+exp(x_axis2));
            
%             
%             figure(111)
%             plot(x_axis1,Pr_all(:,3),'g.')
%             hold
%             plot(x_axis1,Pr_all(:,1),'r.')
%             plot(x_axis1,Pr_all(:,2),'b.')
%             
            
            [decidedSide_P_all, decidedSide_ind]=max(Pr_all');
            
            [side_nom_d decidedSide_ind']
            
            [X1,X2] = ndgrid (-25:0.5:25,-25:0.5:25);%(min(x_axis1):1:max(x_axis1),min(x_axis2):1:max(x_axis2));
            
            Z3=1./(1+exp(X1)+exp(X2));
            Z1=exp(X1)./(1+exp(X1)+exp(X2));
            Z2=exp(X2)./(1+exp(X1)+exp(X2));
            
            
            %     figure(num+10)
           figure(num+30)
            
            %             plot3(X1,X2,Z2,'r.');
            mesh(X1,X2,Z1,'FaceLighting','flat ','EdgeColor','b','LineWidth',0.1);
%             plot3(X1,X2,Z1,'r');
            hold
            plot3(x_axis1,x_axis2,Pr_all(:,1),'b*','LineWidth',4);%mesh(Z2);
            %             plot3(X1,X2,Z3,'b.');
            mesh(X1,X2,Z2,'FaceLighting','flat ','EdgeColor','r','LineWidth',0.1);
%             plot3(X1,X2,Z2,'b');
            plot3(x_axis1,x_axis2,Pr_all(:,2),'r*','LineWidth',4);%   mesh(Z3);
            
            
            mesh(X1,X2,Z3,'FaceLighting','flat ','EdgeColor','g','LineWidth',0.1);  %plot3(X1,X2,Z1,'g.');
%             plot3(X1,X2,Z3,'g');
            plot3(x_axis1,x_axis2,Pr_all(:,3),'g*','LineWidth',4);
            xlim([-50 50]); ylim([-50 50]);
            axis([-30 30 -30 30 0 1]);
           
            zlabel(['Probability of the cases being Unilateral, vs. Bilateral TLE, vs. Control M' num2str(num)],'fontsize',15,'fontweight','b');
            legend( 'Unilateral TLE Logistic Fit','Data Point Classified as Unilateral', 'Bilateral TLE Logistic Fit', 'Bilateral Point Classified as Left', 'Control Logistic Fit', 'Data Point Classified as Control' );
            xlabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            ylabel(['Linear Combination of ' index ' Measurements'],'fontsize',15,'fontweight','b');
            nL=length(find(side_nom_d==2));
            nR=length(find(side_nom_d==1));
            nB=length(find(side_nom_d==3));
            nAll=nL+nR+nB;
            P_D(num) =(length(find(decidedSide_ind(side_nom_d==1)==1))+ length(find(decidedSide_ind(side_nom_d==2)==2))+ length(find(decidedSide_ind(side_nom_d==3)==3)))/nAll;
      
  
    end
    catch
    end
    
    
end

RES=[P_D;dev]
