Pre{1} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_Sub01_v1_PreMAT_29-03-2017_13-49.mat');
Post{1} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_Sub01_v1_PostMAT_29-03-2017_14-19.mat');

Pre{2} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_JQK_2_Pre_27-03-2017_17-49.mat');
Post{2} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_JQK_2_Post_27-03-2017_18-49.mat');

Pre{3} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_JQK_3_Pre_28-03-2017_10-30.mat');
Post{3} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_JQK_3_Post_28-03-2017_11-00.mat');

Pre{4} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_JQK_v5_PreMAT_28-03-2017_18-18.mat');
Post{4} = load('/Volumes/MyPassport3TB/RDM_Distract/MAT_V2/data/dotsX_behav_JQK_v5_PostMAT_28-03-2017_18-47.mat');

%% RTs

for indSub = 1:4
    for indAtt = 1:4
        for indCue = 1:2
            PreResultsAcrossSubs(indSub, indAtt, indCue) = nanmean(Pre{indSub}.ResultMat(Pre{indSub}.ResultMat(:,2) == indAtt & Pre{indSub}.ResultMat(:,1) == indCue,3));
            PostResultsAcrossSubs(indSub, indAtt, indCue) = nanmean(Post{indSub}.ResultMat(Post{indSub}.ResultMat(:,2) == indAtt & Post{indSub}.ResultMat(:,1) == indCue,3));
        end;
    end;
end;
    
figure;
subplot(2,2,1);
    values = [nanmean(PostResultsAcrossSubs(:,1,1))-nanmean(PreResultsAcrossSubs(:,1,1)),...
        nanmean(PostResultsAcrossSubs(:,2,1))-nanmean(PreResultsAcrossSubs(:,2,1)),...
        nanmean(PostResultsAcrossSubs(:,3,1))-nanmean(PreResultsAcrossSubs(:,3,1)),...
        nanmean(PostResultsAcrossSubs(:,4,1))-nanmean(PreResultsAcrossSubs(:,4,1))];
    bar(values, 'FaceColor', [1 .5 0]); ylim([-.4 .4]);
    hold on
    for indAtt = 1:4
        x = PostResultsAcrossSubs(:,indAtt,1)-PreResultsAcrossSubs(:,indAtt,1);
        SEM = std(x)/sqrt(length(x));               % Standard Error
        ts = tinv([0.025  0.975],length(x)-1);      % T-Score
        CI(:,indAtt) = mean(x) + ts*SEM;              % Confidence Intervals
    end;
    e = errorbar(1:4, values, CI(2,:)-values, CI(1,:)-values, 'o');
    e.Color = 'k';
    set(gca,'XTickLabel', Pre{1}.dotInfo.MAT.attNames);
    title('RTs [Cue]');
subplot(2,2,2);
    values = [nanmean(PostResultsAcrossSubs(:,1,2))-nanmean(PreResultsAcrossSubs(:,1,2)),...
        nanmean(PostResultsAcrossSubs(:,2,2))-nanmean(PreResultsAcrossSubs(:,2,2)),...
        nanmean(PostResultsAcrossSubs(:,3,2))-nanmean(PreResultsAcrossSubs(:,3,2)),...
        nanmean(PostResultsAcrossSubs(:,4,2))-nanmean(PreResultsAcrossSubs(:,4,2))];
    bar(values, 'FaceColor', [1 .5 0]); ylim([-.4 .4]);
    hold on
    for indAtt = 1:4
        x = PostResultsAcrossSubs(:,indAtt,2)-PreResultsAcrossSubs(:,indAtt,2);
        SEM = std(x)/sqrt(length(x));               % Standard Error
        ts = tinv([0.025  0.975],length(x)-1);      % T-Score
        CI(:,indAtt) = mean(x) + ts*SEM;              % Confidence Intervals
    end;
    e = errorbar(1:4, values, CI(2,:)-values, CI(1,:)-values, 'o');
    e.Color = 'k';
    set(gca,'XTickLabel', Pre{1}.dotInfo.MAT.attNames);
    title('RTs [no Cue]');

%% Accuracies

for indSub = 1:4
    for indAtt = 1:4
        for indCue = 1:2
            PreResultsAcrossSubs(indSub, indAtt, indCue) = nanmean(Pre{indSub}.ResultMat(Pre{indSub}.ResultMat(:,2) == indAtt & Pre{indSub}.ResultMat(:,1) == indCue,4));
            PostResultsAcrossSubs(indSub, indAtt, indCue) = nanmean(Post{indSub}.ResultMat(Post{indSub}.ResultMat(:,2) == indAtt & Post{indSub}.ResultMat(:,1) == indCue,4));
        end;
    end;
end;
    
%figure;
subplot(2,2,3);
    values = [nanmean(PostResultsAcrossSubs(:,1,1))-nanmean(PreResultsAcrossSubs(:,1,1)),...
        nanmean(PostResultsAcrossSubs(:,2,1))-nanmean(PreResultsAcrossSubs(:,2,1)),...
        nanmean(PostResultsAcrossSubs(:,3,1))-nanmean(PreResultsAcrossSubs(:,3,1)),...
        nanmean(PostResultsAcrossSubs(:,4,1))-nanmean(PreResultsAcrossSubs(:,4,1))];
    bar(values, 'FaceColor', [1 .5 0]); ylim([-.4 .4]);
    hold on
    for indAtt = 1:4
        x = PostResultsAcrossSubs(:,indAtt,1)-PreResultsAcrossSubs(:,indAtt,1);
        SEM = std(x)/sqrt(length(x));               % Standard Error
        ts = tinv([0.025  0.975],length(x)-1);      % T-Score
        CI(:,indAtt) = mean(x) + ts*SEM;              % Confidence Intervals
    end;
    e = errorbar(1:4, values, CI(2,:)-values, CI(1,:)-values, 'o');
    e.Color = 'k';
    set(gca,'XTickLabel', Pre{1}.dotInfo.MAT.attNames);
    title('Accuracies [Cue]');
subplot(2,2,4);
    values = [nanmean(PostResultsAcrossSubs(:,1,2))-nanmean(PreResultsAcrossSubs(:,1,2)),...
        nanmean(PostResultsAcrossSubs(:,2,2))-nanmean(PreResultsAcrossSubs(:,2,2)),...
        nanmean(PostResultsAcrossSubs(:,3,2))-nanmean(PreResultsAcrossSubs(:,3,2)),...
        nanmean(PostResultsAcrossSubs(:,4,2))-nanmean(PreResultsAcrossSubs(:,4,2))];
    bar(values, 'FaceColor', [1 .5 0]); ylim([-.4 .4]);
    hold on
    for indAtt = 1:4
        x = PostResultsAcrossSubs(:,indAtt,2)-PreResultsAcrossSubs(:,indAtt,2);
        SEM = std(x)/sqrt(length(x));               % Standard Error
        ts = tinv([0.025  0.975],length(x)-1);      % T-Score
        CI(:,indAtt) = mean(x) + ts*SEM;              % Confidence Intervals
    end;
    e = errorbar(1:4, values, CI(2,:)-values, CI(1,:)-values, 'o');
    e.Color = 'k';
    set(gca,'XTickLabel', Pre{1}.dotInfo.MAT.attNames);
    title('Accuracies [no Cue]');
