%% 2016/11/21 for the subjects from getSbjFromGroup(5)

addpath('functions/')
%subjects = getSbjFromGroup(5);%update subject names
subjects = {'sbj116', 'sbj117', 'sbj119', 'sbj120', 'sbj121', 'sbj122', 'sbj123', 'sbj124', 'sbj125', 'sbj126'};
mypath = '/data/projects/yute/Glaucoma/nGoggle3/arvo_out/';
mypath2 = '/data/projects/yute/Glaucoma/nGoggle3/tmp_arvo17/';
%mypath = 'd:/raw/preperimetric_out';
%mypath2 = 'd:/raw/preperimetric/';
stimulusA = [1 3 5 7 9 11 14 16 18 20];%condition1
stimulusB = [2 4 6 8 10 12 13 15 17 19];%condition2
invertedStimulusA = [4 2 12 10 8 6 19 17 15 13];
invertedStimulusB = [3 1 11 9 7 5 20 18 16 14];
%freq*LR*sbjs
algorithm1 = zeros(20,2,size(subjects,2));%mean CCA corre
algorithm2 = zeros(20,2,size(subjects,2));%mean CCA power
algorithm3 = zeros(20,2,size(subjects,2));%area of CCA corre (1/3 - 2/3 trials)
algorithm4 = zeros(20,2,size(subjects,2));%area of CCA power (1/3 - 2/3 trials)
algorithm5 = zeros(20,2,size(subjects,2));%area of CCA corre (all trials)
algorithm6 = zeros(20,2,size(subjects,2));%area of CCA corre (all trials)
algorithm7 = zeros(20,2,size(subjects,2));%corre difference of averaging all trials
algorithm8 = zeros(20,2,size(subjects,2));%power difference of averaging all trials
trials = zeros(size(subjects,2),2);%rejection rate, sbjs*(L eye, R eye)
for sbjs = 1:size(subjects,2)
    sbjName = subjects{sbjs};
    name = { [sbjName '_L_A_raw_epoRejected2.set'],[sbjName '_R_A_raw_epoRejected2.set']};
    EEG1 = pop_loadset('filename',name{1},'filepath',mypath);
    EEG1 = eeg_checkset( EEG1 );
    EEG2 = pop_loadset('filename',name{2},'filepath',mypath);
    EEG2 = eeg_checkset( EEG2 );
    
    %algorithm1(invertedStimulusA,1,sbjs) = squeeze(mean(mean(EEG1.laCorr(stimulusA,floor(size(EEG1.laCorr,2)/3:size(EEG1.laCorr,2)*2/3),:),3),2));
    %algorithm1(invertedStimulusB,1,sbjs) = squeeze(mean(mean(EEG1.lbCorr(stimulusB,floor(size(EEG1.lbCorr,2)/3:size(EEG1.lbCorr,2)*2/3),:),3),2));
    algorithm1(invertedStimulusA,1,sbjs) = squeeze(mean(mean(EEG1.raCorr(stimulusA,floor(size(EEG1.raCorr,2)/3:size(EEG1.raCorr,2)*2/3),:),3),2));
    algorithm1(invertedStimulusB,1,sbjs) = squeeze(mean(mean(EEG1.rbCorr(stimulusB,floor(size(EEG1.rbCorr,2)/3:size(EEG1.rbCorr,2)*2/3),:),3),2));
    algorithm1(stimulusA,2,sbjs) = squeeze(mean(mean(EEG2.raCorr(stimulusA,floor(size(EEG2.raCorr,2)/3:size(EEG2.raCorr,2)*2/3),:),3),2));
    algorithm1(stimulusB,2,sbjs) = squeeze(mean(mean(EEG2.rbCorr(stimulusB,floor(size(EEG2.rbCorr,2)/3:size(EEG2.rbCorr,2)*2/3),:),3),2));
%     
%     algorithm2(invertedStimulusA,1,sbjs) = squeeze(mean(mean(EEG1.laPower(stimulusA,floor(size(EEG1.laPower,2)/3:size(EEG1.laPower,2)*2/3),:),3),2));
%     algorithm2(invertedStimulusB,1,sbjs) = squeeze(mean(mean(EEG1.lbPower(stimulusB,floor(size(EEG1.lbPower,2)/3:size(EEG1.lbPower,2)*2/3),:),3),2));
%     algorithm2(stimulusA,2,sbjs) = squeeze(mean(mean(EEG2.raPower(stimulusA,floor(size(EEG2.raPower,2)/3:size(EEG2.raPower,2)*2/3),:),3),2));
%     algorithm2(stimulusB,2,sbjs) = squeeze(mean(mean(EEG2.rbPower(stimulusB,floor(size(EEG2.rbPower,2)/3:size(EEG2.rbPower,2)*2/3),:),3),2));
%     
%     algorithm3(invertedStimulusA,1,sbjs) = mean(mean(EEG1.laCorr(stimulusA,floor(size(EEG1.laCorr,2)/3:size(EEG1.laCorr,2)*2/3),:),3)-mean(EEG1.lbCorr(stimulusA,floor(size(EEG1.lbCorr,2)/3:size(EEG1.lbCorr,2)*2/3),:),3),2);
%     algorithm3(invertedStimulusB,1,sbjs) = mean(mean(EEG1.lbCorr(stimulusB,floor(size(EEG1.lbCorr,2)/3:size(EEG1.laCorr,2)*2/3),:),3)-mean(EEG1.laCorr(stimulusB,floor(size(EEG1.laCorr,2)/3:size(EEG1.laCorr,2)*2/3),:),3),2);
%     algorithm3(stimulusA,2,sbjs) = mean(mean(EEG2.raCorr(stimulusA,floor(size(EEG2.raCorr,2)/3:size(EEG2.raCorr,2)*2/3),:),3)-mean(EEG2.rbCorr(stimulusA,floor(size(EEG2.rbCorr,2)/3:size(EEG2.rbCorr,2)*2/3),:),3),2);
%     algorithm3(stimulusB,2,sbjs) = mean(mean(EEG2.rbCorr(stimulusB,floor(size(EEG2.rbCorr,2)/3:size(EEG2.raCorr,2)*2/3),:),3)-mean(EEG2.raCorr(stimulusB,floor(size(EEG2.raCorr,2)/3:size(EEG2.raCorr,2)*2/3),:),3),2);
%     
%     algorithm4(invertedStimulusA,1,sbjs) = mean(mean(EEG1.laPower(stimulusA,floor(size(EEG1.laPower,2)/3:size(EEG1.laPower,2)*2/3),:),3)-mean(EEG1.lbPower(stimulusA,floor(size(EEG1.lbPower,2)/3:size(EEG1.lbPower,2)*2/3),:),3),2);
%     algorithm4(invertedStimulusB,1,sbjs) = mean(mean(EEG1.lbPower(stimulusB,floor(size(EEG1.lbPower,2)/3:size(EEG1.laPower,2)*2/3),:),3)-mean(EEG1.laPower(stimulusB,floor(size(EEG1.laPower,2)/3:size(EEG1.laPower,2)*2/3),:),3),2);
%     algorithm4(stimulusA,2,sbjs) = mean(mean(EEG2.raPower(stimulusA,floor(size(EEG2.raPower,2)/3:size(EEG2.raPower,2)*2/3),:),3)-mean(EEG2.rbPower(stimulusA,floor(size(EEG2.rbPower,2)/3:size(EEG2.rbPower,2)*2/3),:),3),2);
%     algorithm4(stimulusB,2,sbjs) = mean(mean(EEG2.rbPower(stimulusB,floor(size(EEG2.rbPower,2)/3:size(EEG2.raPower,2)*2/3),:),3)-mean(EEG2.raPower(stimulusB,floor(size(EEG2.raPower,2)/3:size(EEG2.raPower,2)*2/3),:),3),2);
%     
%     algorithm5(invertedStimulusA,1,sbjs) = mean(mean(EEG1.laCorr(stimulusA,:,:),3)-mean(EEG1.lbCorr(stimulusA,:,:),3),2);
%     algorithm5(invertedStimulusB,1,sbjs) = mean(mean(EEG1.lbCorr(stimulusB,:,:),3)-mean(EEG1.laCorr(stimulusB,:,:),3),2);
%     algorithm5(stimulusA,2,sbjs) = mean(mean(EEG2.raCorr(stimulusA,:,:),3)-mean(EEG2.rbCorr(stimulusA,:,:),3),2);
%     algorithm5(stimulusB,2,sbjs) = mean(mean(EEG2.rbCorr(stimulusB,:,:),3)-mean(EEG2.raCorr(stimulusB,:,:),3),2);
%     
%     algorithm6(invertedStimulusA,1,sbjs) = mean(mean(EEG1.laPower(stimulusA,:,:),3)-mean(EEG1.lbPower(stimulusA,:,:),3),2);
%     algorithm6(invertedStimulusB,1,sbjs) = mean(mean(EEG1.lbPower(stimulusB,:,:),3)-mean(EEG1.laPower(stimulusB,:,:),3),2);
%     algorithm6(stimulusA,2,sbjs) = mean(mean(EEG2.raPower(stimulusA,:,:),3)-mean(EEG2.rbPower(stimulusA,:,:),3),2);
%     algorithm6(stimulusB,2,sbjs) = mean(mean(EEG2.rbPower(stimulusB,:,:),3)-mean(EEG2.raPower(stimulusB,:,:),3),2);
%     
%     algorithm7(invertedStimulusA,1,sbjs) = mean(EEG1.laCorr(stimulusA,end,:),3)-mean(EEG1.lbCorr(stimulusA,end,:),3);
%     algorithm7(invertedStimulusB,1,sbjs) = mean(EEG1.lbCorr(stimulusB,end,:),3)-mean(EEG1.laCorr(stimulusB,end,:),3);
%     algorithm7(stimulusA,2,sbjs) = mean(EEG2.raCorr(stimulusA,end,:),3)-mean(EEG2.rbCorr(stimulusA,end,:),3);
%     algorithm7(stimulusB,2,sbjs) = mean(EEG2.rbCorr(stimulusB,end,:),3)-mean(EEG2.raCorr(stimulusB,end,:),3);
%     
%     algorithm8(invertedStimulusA,1,sbjs) = mean(EEG1.laPower(stimulusA,end,:),3)-mean(EEG1.lbPower(stimulusA,end,:),3);
%     algorithm8(invertedStimulusB,1,sbjs) = mean(EEG1.lbPower(stimulusB,end,:),3)-mean(EEG1.laPower(stimulusB,end,:),3);
%     algorithm8(stimulusA,2,sbjs) = mean(EEG2.raPower(stimulusA,end,:),3)-mean(EEG2.rbPower(stimulusA,end,:),3);
%     algorithm8(stimulusB,2,sbjs) = mean(EEG2.rbPower(stimulusB,end,:),3)-mean(EEG2.raPower(stimulusB,end,:),3);

    name = { [sbjName '_L_A_raw_epoRejected.set'],[sbjName '_R_A_raw_epoRejected.set']};
    EEG3 = pop_loadset('filename',name{1},'filepath',mypath2);
    EEG3 = eeg_checkset( EEG3 );
    EEG4 = pop_loadset('filename',name{2},'filepath',mypath2);
    EEG4 = eeg_checkset( EEG4 );
    trials(sbjs,1) = EEG3.numRejTrials/EEG3.numOriTrials;
    trials(sbjs,2) = EEG4.numRejTrials/EEG4.numOriTrials;
    
end
saveFile = [mypath 'group6'];
%save(saveFile,'algorithm1','algorithm2','algorithm3','algorithm4','algorithm5','algorithm6','trials','algorithm7','algorithm8');
save(saveFile,'algorithm1', 'trials');
