function [DataB,GLMout]=generate_fMRI_GLMS(DataB,fMRIGLM_info)
%keyboard;
for Isub=1:length(DataB.Subject)
    
    % Compute timings
    OnsetPulses=DataB.Subject(Isub).timings.Pulses/10000;
    empiricalTRs=OnsetPulses(2:end)-OnsetPulses(1:end-1);
    FirstRecordedVolume=find((empiricalTRs<1.51) & (empiricalTRs>1.49),1,'first');
    FirstPulse=OnsetPulses(FirstRecordedVolume);
    OnsetTrial=DataB.Subject(Isub).timings.TimeWelcome/10000-FirstPulse;     % In seconds;
    OnsetQU=DataB.Subject(Isub).timings.TimeQuestionyou/10000-FirstPulse;     % In seconds;
    OnsetQO=DataB.Subject(Isub).timings.TimeQuestionother/10000-FirstPulse;     % In seconds;
    OnsetAU=DataB.Subject(Isub).timings.TimeAnsweryou/10000-FirstPulse;     % In seconds;
    OnsetAO=DataB.Subject(Isub).timings.TimeAnswerother/10000-FirstPulse;     % In seconds;
    OnsetSamples=DataB.Subject(Isub).timings.TimeAllSamples/10000-FirstPulse;     % In seconds;
    
    
    
    switch fMRIGLM_info.fMRIDesignName
        
        case 'ChosenEvidenceAnalysis'
            ChoiceSelfMainEffectLabel={'MainEffectSelfChoice'};
            LabelsDesignMatrixChoiceSelf={'SD_ChOccEvid';'SD_ChSharedEvid'};
            DesignMatrixChoiceSelf=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.self.redchoice(:,Isub))  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.self.redchoice(:,Isub))];
            ChoiceSelfOnsets=OnsetQU;
            ChoiceSelfDurations=zeros(size(OnsetQU,1),1);
            
            ChoiceOtherMainEffectLabel={'MainEffectOtherChoice'};
            LabelsDesignMatrixChoiceOther={'OD_ChOccEvid';'OD_ChSharedEvid'};
            DesignMatrixChoiceOther=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.other.redchoice(:,Isub))  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.other.redchoice(:,Isub))];
            ChoiceOtherOnsets=OnsetQO;
            ChoiceOtherDurations=zeros(size(OnsetQO,1),1);
            
            SamplingMainEffectLabel={'MainEffectSampling'};
            LabelsDesignMatrixSampling={'occludedSample';'sharedSample';'Samplenr'};
            DesignMatrixSampling=[DataB.stacked{Isub}.occlSamples DataB.stacked{Isub}.sharedSamples  DataB.stacked{Isub}.SampleNr];
            SamplingOnsets=OnsetSamples;
            SamplingDurations=zeros(size(SamplingOnsets,1),1);

            OutcomeMainEffectLabel={'MainEffectOutcome'};
            LabelsDesignMatrixOutcome={'CorrectOther';'AgentAbility';'CorrectByAgentAbility'};  % As in the matrix 1=Good Agent, 2=Bad Agent, I flip this so that high values are good ability
            DesignMatrixOutcome=[ DataB.decision.other.correct(:,Isub) 3-DataB.AgentAbilityLvl(:,Isub) ((1.5-DataB.AgentAbilityLvl(:,Isub)).*2).*zscore(DataB.decision.other.correct(:,Isub))];
            OutcomeOnsets=OnsetAO;  % What is the exact onset of the Outcome period?
            OutcomeDurations=zeros(size(OutcomeOnsets,1),1);
            
            % make contrast Matrix from regressors
            
            % Start by stacking all regressors together with constants
            RegressorLabels=[ChoiceSelfMainEffectLabel;LabelsDesignMatrixChoiceSelf;ChoiceOtherMainEffectLabel;LabelsDesignMatrixChoiceOther;...
                SamplingMainEffectLabel;LabelsDesignMatrixSampling;OutcomeMainEffectLabel;LabelsDesignMatrixOutcome];
            ContrastLabels=RegressorLabels;
            ContrastWeights=diag(ones(length(RegressorLabels),1));
            
            %Now the others
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionMainEffects';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectSelfChoice'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectOtherChoice'))=1;
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_DecisionMainEffects';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectSelfChoice'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectOtherChoice'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_DecisionChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_DecisionChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SelfDec_AllEvidence';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OtherDec_AllEvidence';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_AllEvidence';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_ShvsOc_SelfDec';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_ShvsOc_OtherDec';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_ShvsOc_SvsO';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='AllSamples';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'occludedSample'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'sharedSample'))=1;
            
        case 'AgentSpecificChosenEvidenceAnalysis'
            GoodAgentOnly=nan(size(DataB.AgentAbilityLvl(:,Isub)));
            BadAgentOnly =nan(size(DataB.AgentAbilityLvl(:,Isub)));
            GoodAgentOnly(DataB.AgentAbilityLvl(:,Isub)==1)=1;
            BadAgentOnly(DataB.AgentAbilityLvl(:,Isub)==2)=1;
            ChoiceSelfMainEffectLabel={'MainEffectSelfChoice'};
            LabelsDesignMatrixChoiceSelf={'SD_ChOccEvidGoodAgent';'SD_ChSharedEvidGoodAgent';'SD_ChOccEvidBadAgent';'SD_ChSharedEvidBadAgent';'SD_AgentAbility'};
            DesignMatrixChoiceSelf=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.self.redchoice(:,Isub)).*GoodAgentOnly  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.self.redchoice(:,Isub)).*GoodAgentOnly ...
                (DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.self.redchoice(:,Isub)).*BadAgentOnly  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.self.redchoice(:,Isub)).*BadAgentOnly ...
                3-DataB.AgentAbilityLvl(:,Isub)];
            ChoiceSelfOnsets=OnsetQU;
            ChoiceSelfDurations=zeros(size(OnsetQU,1),1);
            
            ChoiceOtherMainEffectLabel={'MainEffectOtherChoice'};
            LabelsDesignMatrixChoiceOther={'OD_ChOccEvidGoodAgent';'OD_ChSharedEvidGoodAgent';'OD_ChOccEvidBadAgent';'OD_ChSharedEvidBadAgent';'OD_AgentAbility'};
            DesignMatrixChoiceOther=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.other.redchoice(:,Isub)).*GoodAgentOnly  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.other.redchoice(:,Isub)).*GoodAgentOnly ...
                (DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.other.redchoice(:,Isub)).*BadAgentOnly  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.other.redchoice(:,Isub)).*BadAgentOnly ...
                3-DataB.AgentAbilityLvl(:,Isub)];
            ChoiceOtherOnsets=OnsetQO;
            ChoiceOtherDurations=zeros(size(OnsetQO,1),1);
            
            SamplingMainEffectLabel={'MainEffectSampling'};
            LabelsDesignMatrixSampling={'occludedSampleGoodAgent';'sharedSampleGoodAgent';'occludedSampleBadAgent';'sharedSampleBadAgent';'Samplenr';'Sampling_AgentAbility'};
            GoodAgentOnlyStacked=nan(size(DataB.stacked{Isub}.AgentAbilitylvl));
            BadAgentOnlyStacked =nan(size(DataB.stacked{Isub}.AgentAbilitylvl));
            GoodAgentOnlyStacked(DataB.stacked{Isub}.AgentAbilitylvl==2)=1;
            BadAgentOnlyStacked(DataB.stacked{Isub}.AgentAbilitylvl==1)=1;
            DesignMatrixSampling=[DataB.stacked{Isub}.occlSamples.*GoodAgentOnlyStacked DataB.stacked{Isub}.sharedSamples.*GoodAgentOnlyStacked ...
                DataB.stacked{Isub}.occlSamples.*BadAgentOnlyStacked DataB.stacked{Isub}.sharedSamples.*BadAgentOnlyStacked ...
                DataB.stacked{Isub}.SampleNr 3-DataB.stacked{Isub}.AgentAbilitylvl];
            SamplingOnsets=OnsetSamples;
            SamplingDurations=zeros(size(SamplingOnsets,1),1);
            
            OutcomeMainEffectLabel={'MainEffectOutcome'};
            LabelsDesignMatrixOutcome={'CorrectOtherGoodAgent';'CorrectOtherBadAgent';'AgentAbility'}; %
            DesignMatrixOutcome=[ DataB.decision.other.correct(:,Isub).*GoodAgentOnly DataB.decision.other.correct(:,Isub).*BadAgentOnly   3-DataB.AgentAbilityLvl(:,Isub)];
            OutcomeOnsets=OnsetAO;  % What is the exact onset of the Outcome period?
            OutcomeDurations=zeros(size(OutcomeOnsets,1),1);
            
            % Start by stacking all regressors together with constants
            RegressorLabels=[ChoiceSelfMainEffectLabel;LabelsDesignMatrixChoiceSelf;ChoiceOtherMainEffectLabel;LabelsDesignMatrixChoiceOther;...
                SamplingMainEffectLabel;LabelsDesignMatrixSampling;OutcomeMainEffectLabel;LabelsDesignMatrixOutcome];
            ContrastLabels=RegressorLabels;
            ContrastWeights=diag(ones(length(RegressorLabels),1));
            
            %Now the others
            %SelfDec
            ContrastLabels{length(ContrastLabels)+1}='SD_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SD_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SD_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SD_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SD_AgentDif_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SD_AgentDif_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SD_AgentDif_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SD_AgentDif_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            %OtherDec
            ContrastLabels{length(ContrastLabels)+1}='OD_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OD_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OD_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OD_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OD_AgentDif_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='OD_AgentDif_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='OD_AgentDif_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='OD_AgentDif_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            
            %Now combinations of Self-Other
            ContrastLabels{length(ContrastLabels)+1}='Both_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Both_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Both_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Both_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Both_AgentDif_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Both_AgentDif_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Both_AgentDif_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Both_AgentDif_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            %Now Comparison of Self-Other
            ContrastLabels{length(ContrastLabels)+1}='SvsO_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_AgentDif_ChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_AgentDif_ChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_AgentDif_AllEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SvsO_AgentDif_Dif_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvidBadAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidGoodAgent'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvidBadAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidGoodAgent'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvidBadAgent'))=1;
            
        case 'ChoiceDivergenceAnalysis'
            ChoiceDivergence=DataB.decision.self.redchoice(:,Isub)~=DataB.decision.other.redchoice(:,Isub);
            PriorSharedEvidSign=2.*DataB.stacked{Isub}.stackedPriorEvidenceShared>1-1;
            PriorOverallEvidSign=2.*DataB.stacked{Isub}.stackedPriorEvidenceAll>1-1;
            SharedSamples=DataB.stacked{Isub}.sharedSamples;
            SharedSamples(SharedSamples==0)=nan;
            OccludedSamples=DataB.stacked{Isub}.occlSamples;
            OccludedSamples(OccludedSamples==0)=nan;
            
            
            PriorAreDivergent=PriorSharedEvidSign~=PriorOverallEvidSign;
            ConfirmDiff=nan(length(DataB.stacked{Isub}.sharedSamples),1);
            ConfirmDiff(PriorAreDivergent)=PriorOverallEvidSign(PriorAreDivergent).*DataB.stacked{Isub}.sharedSamples(PriorAreDivergent);
            
            % For sample stage: prior shared sampleconfirm occludedcountersample
            % Do analyses of evidence in decision phase when they agree or disagree for other choices?
            ChoiceSelfMainEffectLabel={'MainEffectSelfChoice'};
            LabelsDesignMatrixChoiceSelf={'SD_counterOccEvid';'SD_absSharedEvid'};
            signFlip=2*(DataB.evidence.Other(:,Isub)>0)-1;
            DesignMatrixChoiceSelf=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*-signFlip  ...
                abs(DataB.evidence.Other(:,Isub))];
            ChoiceSelfOnsets=OnsetQU;
            ChoiceSelfDurations=zeros(size(OnsetQU,1),1);
            
            ChoiceOtherMainEffectLabel={'MainEffectOtherChoice'};
            LabelsDesignMatrixChoiceOther={'OD_counterOccEvid';'OD_absSharedEvid'};
            signFlip=2*(DataB.evidence.Other(:,Isub)>0)-1;
            DesignMatrixChoiceOther=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*-signFlip  ...
                abs(DataB.evidence.Other(:,Isub)) ];
            ChoiceOtherOnsets=OnsetQO;
            ChoiceOtherDurations=zeros(size(OnsetQO,1),1);
            
            SamplingMainEffectLabel={'MainEffectSampling'};
            LabelsDesignMatrixSampling={'occludedvssharedMainDiff';'occludedcounterevid';'sharedEvidconfirm';'ConfirmDiffIncldOccludeEVid';...
                'AbsSharedPriorEvid';'Samplenr';'AgentAbility'};
            DesignMatrixSampling=[abs(DataB.stacked{Isub}.occlSamples)>0 OccludedSamples.*-PriorSharedEvidSign ...
                SharedSamples.*PriorSharedEvidSign ConfirmDiff  ...
                abs(DataB.stacked{Isub}.stackedPriorEvidenceShared)  DataB.stacked{Isub}.SampleNr  3-DataB.stacked{Isub}.AgentAbilitylvl];
            SamplingOnsets=OnsetSamples;
            SamplingDurations=zeros(size(SamplingOnsets,1),1); %stackedPriorEvidenceShared
            
            OutcomeMainEffectLabel={'MainEffectOutcome'};
            LabelsDesignMatrixOutcome={'CorrectOther';'AgentAbility';'CorrectByAgentAbility';'ChoiceDivergence';'CorrectByDivergence'};  % As in the matrix 1=Good Agent, 2=Bad Agent, I flip this so that high values are good ability
            DesignMatrixOutcome=[ DataB.decision.other.correct(:,Isub) 3-DataB.AgentAbilityLvl(:,Isub) ...
                ((1.5-DataB.AgentAbilityLvl(:,Isub)).*2).*zscore(DataB.decision.other.correct(:,Isub)) ...
                ChoiceDivergence  zscore(ChoiceDivergence).*zscore(DataB.decision.other.correct(:,Isub))];
            OutcomeOnsets=OnsetAO;  % What is the exact onset of the Outcome period?
            OutcomeDurations=zeros(size(OutcomeOnsets,1),1);
            
            % make contrast Matrix from regressors
            
            % Start by stacking all regressors together with constants
            RegressorLabels=[ChoiceSelfMainEffectLabel;LabelsDesignMatrixChoiceSelf;ChoiceOtherMainEffectLabel;LabelsDesignMatrixChoiceOther;...
                SamplingMainEffectLabel;LabelsDesignMatrixSampling;OutcomeMainEffectLabel;LabelsDesignMatrixOutcome];
            ContrastLabels=RegressorLabels;
            ContrastWeights=diag(ones(length(RegressorLabels),1));
            
            %Now the others
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionMainEffects';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectSelfChoice'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectOtherChoice'))=1;
            ContrastLabels{length(ContrastLabels)+1}='counterOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_counterOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_counterOccEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SDvsOD_counterOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_counterOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_counterOccEvid'))=-1;
            
            ContrastLabels{length(ContrastLabels)+1}='absSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_absSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_absSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='SDvsOD_absSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_absSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_absSharedEvid'))=-1;
            
            ContrastLabels{length(ContrastLabels)+1}='SD_sharedvscounterOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_counterOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_absSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OD_sharedvscounterOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_counterOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_absSharedEvid'))=1;
            
            ContrastLabels{length(ContrastLabels)+1}='sharedvscounterOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_counterOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_absSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_counterOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_absSharedEvid'))=1;
            
            ContrastLabels{length(ContrastLabels)+1}='SDvsOD_sharedvscounterOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_counterOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_absSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_counterOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_absSharedEvid'))=-1;
            
            ContrastLabels{length(ContrastLabels)+1}='Sampling_confsharedvsdisconfOccluded';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'occludedcounterevid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'sharedEvidconfirm'))=1;
            
            ContrastLabels{length(ContrastLabels)+1}='confirmvsPrior';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'AbsSharedPriorEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'sharedEvidconfirm'))=1;
            
            ContrastLabels{length(ContrastLabels)+1}='occdisconfirmvsPrior';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'AbsSharedPriorEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'occludedcounterevid'))=1;
            
            ContrastLabels{length(ContrastLabels)+1}='sharedEvidvsConfirmDiffinclOccludeEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'ConfirmDiffIncldOccludeEVid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'sharedEvidconfirm'))=1;
            
            %'occludedvssharedMainDiff';'occludedcounterevid';'sharedEvidconfirm';'ConfirmDiffIncldOccludeEVid';'AbsSharedPriorEvid';
        
        case 'Correctness_DivergenceAnalysis'
        keyboard
        
        
        
        case 'Sampling_ChosenEvid'
        
            occlSample=abs(DataB.stacked{Isub}.occlSamples)>0;
            OverallSaNr_occl=nan(length(DataB.stacked{Isub}.SampleNr),1);
            OverallSaNr_Shared=nan(length(DataB.stacked{Isub}.SampleNr),1);
            OverallSaNr_occl(occlSample)=DataB.stacked{Isub}.SampleNr(occlSample);
            OverallSaNr_Shared(~occlSample)=DataB.stacked{Isub}.SampleNr(~occlSample);

            occludedAmountevid_perSample=nan(length(DataB.stacked{Isub}.occlSamples),1);
            SharedAmountevid_perSample=nan(length(DataB.stacked{Isub}.occlSamples),1);
            
           occludedAmountevid_perSample(abs(DataB.stacked{Isub}.occlSamples)>0)= DataB.stacked{Isub}.occlSamples(abs(DataB.stacked{Isub}.occlSamples)>0);
           SharedAmountevid_perSample(abs(DataB.stacked{Isub}.sharedSamples)>0)= DataB.stacked{Isub}.sharedSamples(abs(DataB.stacked{Isub}.sharedSamples)>0) ;


            
             SamplingMainEffectLabel={'MainEffectSampling'};
            LabelsDesignMatrixSampling={'occludedvssharedMainDiff';'occludedAmountevid';'sharedAmountevid';'OverallSamplenr_shared';'OverallSamplenr_occl'}; %;'occl_Samplenr_occl'
            
            DesignMatrixSampling=[occlSample occludedAmountevid_perSample SharedAmountevid_perSample ...
            OverallSaNr_Shared OverallSaNr_occl  ]; %DataB.stacked{Isub}.OcclSampleNr
            
            SamplingOnsets=OnsetSamples;
            SamplingDurations=zeros(size(SamplingOnsets,1),1); %stackedPriorEvidenceShared
            
             ChoiceSelfMainEffectLabel={'MainEffectSelfChoice'};
            LabelsDesignMatrixChoiceSelf={'SD_ChOccEvid';'SD_ChSharedEvid'};
            DesignMatrixChoiceSelf=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.self.redchoice(:,Isub))  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.self.redchoice(:,Isub))];
            ChoiceSelfOnsets=OnsetQU;
            ChoiceSelfDurations=zeros(size(OnsetQU,1),1);
            
            ChoiceOtherMainEffectLabel={'MainEffectOtherChoice'};
            LabelsDesignMatrixChoiceOther={'OD_ChOccEvid';'OD_ChSharedEvid'};
            DesignMatrixChoiceOther=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*(1-2.*DataB.decision.other.redchoice(:,Isub))  ...
                DataB.evidence.Other(:,Isub).*(1-2.*DataB.decision.other.redchoice(:,Isub))];
            ChoiceOtherOnsets=OnsetQO;
            ChoiceOtherDurations=zeros(size(OnsetQO,1),1);
            
            
           
                       
            OutcomeMainEffectLabel={'MainEffectOutcome'};
            LabelsDesignMatrixOutcome={'CorrectOther'};  % As in the matrix 1=Good Agent, 2=Bad Agent, I flip this so that high values are good ability
            DesignMatrixOutcome=[ DataB.decision.other.correct(:,Isub)];
            OutcomeOnsets=OnsetAO;  % What is the exact onset of the Outcome period?
            OutcomeDurations=zeros(size(OutcomeOnsets,1),1);
            
            
            
             % make contrast Matrix from regressors
            
            % Start by stacking all regressors together with constants
            RegressorLabels=[ChoiceSelfMainEffectLabel;LabelsDesignMatrixChoiceSelf;ChoiceOtherMainEffectLabel;LabelsDesignMatrixChoiceOther;...
                SamplingMainEffectLabel;LabelsDesignMatrixSampling;OutcomeMainEffectLabel;LabelsDesignMatrixOutcome];
            ContrastLabels=RegressorLabels;
            ContrastWeights=diag(ones(length(RegressorLabels),1));
            
            %Now the others
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionMainEffects';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectSelfChoice'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectOtherChoice'))=1;
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='BothDecisionChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_DecisionMainEffects';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectSelfChoice'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'MainEffectOtherChoice'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_DecisionChOccEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_DecisionChSharedEvid';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='SelfDec_AllEvidence';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OtherDec_AllEvidence';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_SvsO_AllEvidence';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_ShvsOc_SelfDec';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_ShvsOc_OtherDec';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='Diff_ShvsOc_SvsO';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChOccEvid'))=-1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'SD_ChSharedEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChOccEvid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OD_ChSharedEvid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='AmountEvidAtSample';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'occludedAmountevid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'sharedAmountevid'))=1;
            ContrastLabels{length(ContrastLabels)+1}='AmountEvidAtSample_OcvsSh';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'occludedAmountevid'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'sharedAmountevid'))=-1;
            ContrastLabels{length(ContrastLabels)+1}='OverallSamplenr';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OverallSamplenr_shared'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OverallSamplenr_occl'))=1;
            ContrastLabels{length(ContrastLabels)+1}='OverallSamplenr_ShvsOc';
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OverallSamplenr_shared'))=1;
            ContrastWeights(length(ContrastLabels),strcmp(RegressorLabels,'OverallSamplenr_occl'))=-1;            

            
            
        case 'TC_Analysis'
            ChoiceDivergence=DataB.decision.self.redchoice(:,Isub)~=DataB.decision.other.redchoice(:,Isub);
            PriorSharedEvidSign=2.*DataB.stacked{Isub}.stackedPriorEvidenceShared>1-1;
            PriorOverallEvidSign=2.*DataB.stacked{Isub}.stackedPriorEvidenceAll>1-1;
            SharedSamples=DataB.stacked{Isub}.sharedSamples;
            SharedSamples(SharedSamples==0)=nan;
            OccludedSamples=DataB.stacked{Isub}.occlSamples;
            OccludedSamples(OccludedSamples==0)=nan;
            
            
            PriorAreDivergent=PriorSharedEvidSign~=PriorOverallEvidSign;
            ConfirmDiff=nan(length(DataB.stacked{Isub}.sharedSamples),1);
            ConfirmDiff(PriorAreDivergent)=PriorOverallEvidSign(PriorAreDivergent).*DataB.stacked{Isub}.sharedSamples(PriorAreDivergent);
            
            % For sample stage: prior shared sampleconfirm occludedcountersample
            % Do analyses of evidence in decision phase when they agree or disagree for other choices?
            ChoiceSelfMainEffectLabel={'MainEffectSelfChoice'};
            LabelsDesignMatrixChoiceSelf={'SD_counterOccEvid';'SD_absSharedEvid'};
            signFlip=2*(DataB.evidence.Other(:,Isub)>0)-1;
            DesignMatrixChoiceSelf=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*-signFlip  ...
                abs(DataB.evidence.Other(:,Isub))];
            ChoiceSelfOnsets=OnsetQU;
            ChoiceSelfDurations=zeros(size(OnsetQU,1),1);
            
            ChoiceOtherMainEffectLabel={'MainEffectOtherChoice'};
            LabelsDesignMatrixChoiceOther={'OD_counterOccEvid';'OD_absSharedEvid'};
            signFlip=2*(DataB.evidence.Other(:,Isub)>0)-1;
            DesignMatrixChoiceOther=[(DataB.evidence.Overall(:,Isub)-DataB.evidence.Other(:,Isub)).*-signFlip  ...
                abs(DataB.evidence.Other(:,Isub)) ];
            ChoiceOtherOnsets=OnsetQO;
            ChoiceOtherDurations=zeros(size(OnsetQO,1),1);
            
            SamplingMainEffectLabel={'MainEffectSampling'};
            LabelsDesignMatrixSampling={'occludedvssharedMainDiff';'occludedcounterevid';'sharedEvidconfirm';'ConfirmDiffIncldOccludeEVid';...
                'AbsSharedPriorEvid';'Samplenr';'AgentAbility'};
            DesignMatrixSampling=[abs(DataB.stacked{Isub}.occlSamples)>0 OccludedSamples.*-PriorSharedEvidSign ...
                SharedSamples.*PriorSharedEvidSign ConfirmDiff  ...
                abs(DataB.stacked{Isub}.stackedPriorEvidenceShared)  DataB.stacked{Isub}.SampleNr  3-DataB.stacked{Isub}.AgentAbilitylvl];
            SamplingOnsets=OnsetSamples;
            SamplingDurations=zeros(size(SamplingOnsets,1),1); %stackedPriorEvidenceShared
            
            OutcomeMainEffectLabel={'MainEffectOutcome'};
            LabelsDesignMatrixOutcome={'CorrectOther';'AgentAbility';'CorrectByAgentAbility';'ChoiceDivergence';'CorrectByDivergence'};  % As in the matrix 1=Good Agent, 2=Bad Agent, I flip this so that high values are good ability
            DesignMatrixOutcome=[ DataB.decision.other.correct(:,Isub) 3-DataB.AgentAbilityLvl(:,Isub) ...
                ((1.5-DataB.AgentAbilityLvl(:,Isub)).*2).*zscore(DataB.decision.other.correct(:,Isub)) ...
                ChoiceDivergence  zscore(ChoiceDivergence).*zscore(DataB.decision.other.correct(:,Isub))];
            OutcomeOnsets=OnsetAO;  % What is the exact onset of the Outcome period?
            OutcomeDurations=zeros(size(OutcomeOnsets,1),1);
            
            % make contrast Matrix from regressors
            
            % Start by stacking all regressors together with constants
            RegressorLabels=[ChoiceSelfMainEffectLabel;LabelsDesignMatrixChoiceSelf;ChoiceOtherMainEffectLabel;LabelsDesignMatrixChoiceOther;...
                SamplingMainEffectLabel;LabelsDesignMatrixSampling;OutcomeMainEffectLabel;LabelsDesignMatrixOutcome];
            ContrastLabels=RegressorLabels;
            ContrastWeights=diag(ones(length(RegressorLabels),1));
    end
    
    if Isub==1
        figure('color',[1 1 1],'name','Contrasts');imagesc(ContrastWeights,[-1 1]);hold on;
        %set(gca,'XTicklabelrotation',45);set(gca,'XTick',1:length(ContrastLabels));set(gca,'XTicklabel',ContrastLabels);
        set(gca,'YTick',1:length(ContrastLabels));set(gca,'YTicklabel',ContrastLabels);
        set(gca,'fontsize',14);
    end
    % make indices
    switch  fMRIGLM_info.SelfChoiceSelection
        case 'AllChoicesSelf'
            IndexGLMSelfChoices           =ones(size(DataB.decision.self.correct(:,Isub),1),1);
    end
    IndexGLMSelfChoices=IndexGLMSelfChoices==1;
    switch  fMRIGLM_info.OtherChoiceSelection
        case 'AllChoicesOther'
            IndexGLMOtherChoices           =ones(size(DataB.decision.other.correct(:,Isub),1),1);
    end
    IndexGLMOtherChoices=IndexGLMOtherChoices==1;
    switch  fMRIGLM_info.SamplingSelection
        case 'AllSamples'
            IndexGLMSamples           =ones(length(DataB.stacked{Isub}.sharedSamples),1);
    end
    IndexGLMSamples=IndexGLMSamples==1;
    switch  fMRIGLM_info.Outcomeselection
        case 'AllOutcomes'
            % There is always a self and other outcome so I could take either.
            %Also both outcomes are not temporally dissociated.
            IndexGLMOutcome         =ones(size(DataB.decision.self.correct(:,Isub),1),1);
    end
    IndexGLMOutcome=IndexGLMOutcome==1;
    
    % Normalize regressors after ignoring nans and substituting them with
    % zeros
    
    % normalise design matrices by zscoring
    for NrC = 1:size(DesignMatrixChoiceSelf,2)
        DesignMatrixChoiceSelf(~isnan(DesignMatrixChoiceSelf(:,NrC)),NrC)=zscore(DesignMatrixChoiceSelf(~isnan(DesignMatrixChoiceSelf(:,NrC)),NrC));
    end
    DesignMatrixChoiceSelf(isnan(DesignMatrixChoiceSelf))=0;   % After normalization, substitute NaN's with zeros
    for NrC = 1:size(DesignMatrixChoiceOther,2)
        DesignMatrixChoiceOther(~isnan(DesignMatrixChoiceOther(:,NrC)),NrC)=zscore(DesignMatrixChoiceOther(~isnan(DesignMatrixChoiceOther(:,NrC)),NrC));
    end
    DesignMatrixChoiceOther(isnan(DesignMatrixChoiceOther))=0;   % After normalization, substitute NaN's with zeros
    for NrC = 1:size(DesignMatrixSampling,2)
        DesignMatrixSampling(~isnan(DesignMatrixSampling(:,NrC)),NrC)=zscore(DesignMatrixSampling(~isnan(DesignMatrixSampling(:,NrC)),NrC));
    end
    DesignMatrixSampling(isnan(DesignMatrixSampling))=0;   % After normalization, substitute NaN's with zeros
    for NrC = 1:size(DesignMatrixOutcome,2)
        DesignMatrixOutcome(~isnan(DesignMatrixOutcome(:,NrC)),NrC)=zscore(DesignMatrixOutcome(~isnan(DesignMatrixOutcome(:,NrC)),NrC));
    end
    DesignMatrixOutcome(isnan(DesignMatrixOutcome))=0;   % After normalization, substitute NaN's with zeros
    
    % Make correlation matrices
    DesignCorrelationsChoiceSelf(:,:,Isub)=corrcoef(DesignMatrixChoiceSelf(IndexGLMSelfChoices,:));
    DesignCorrelationsChoiceOther(:,:,Isub)=corrcoef(DesignMatrixChoiceOther(IndexGLMOtherChoices,:));
    DesignCorrelationsSampling(:,:,Isub)=corrcoef(DesignMatrixSampling(IndexGLMSamples,:));
    DesignCorrelationsOutcome(:,:,Isub)=corrcoef(DesignMatrixOutcome(IndexGLMOutcome,:));
    
    % keyboard;
    %% make folders if they do not exists
    
    
    DesignFilesFolder=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs');
    if  ~exist(DesignFilesFolder,'file')
        disp(['making folder ' DesignFilesFolder ' as it does not exist'])
        mkdir(DesignFilesFolder);
    else
        disp([DesignFilesFolder ' exists already!!! Contents will possibly be overwritten'])
    end
    
    SubjectFilesFolder=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,DataB.ID{Isub});
    if  ~exist(SubjectFilesFolder,'file')
        disp(['making folder ' SubjectFilesFolder ' as it does not exist'])
        mkdir(SubjectFilesFolder);
    else
        disp([SubjectFilesFolder ' exists already!!! Contents will possibly be overwritten'])
    end
    
    
    DesignFilesFolder_selfChoices=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,DataB.ID{Isub},'SelfChoices');
    if  ~exist(DesignFilesFolder_selfChoices,'file')
        disp(['making folder ' DesignFilesFolder_selfChoices ' as it does not exist'])
        mkdir(DesignFilesFolder_selfChoices);
    else
        disp([DesignFilesFolder_selfChoices ' exists already!!! Contents will possibly be overwritten'])
    end
    
    DesignFilesFolder_otherChoices=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,DataB.ID{Isub},'OtherChoices');
    if  ~exist(DesignFilesFolder_otherChoices,'file')
        disp(['making folder ' DesignFilesFolder_otherChoices ' as it does not exist'])
        mkdir(DesignFilesFolder_otherChoices);
    else
        disp([DesignFilesFolder_otherChoices ' exists already!!! Contents will possibly be overwritten'])
    end
    
    DesignFilesFolder_samples=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,DataB.ID{Isub},'Samples');
    if  ~exist(DesignFilesFolder_samples,'file')
        disp(['making folder ' DesignFilesFolder_samples ' as it does not exist'])
        mkdir(DesignFilesFolder_samples);
    else
        disp([DesignFilesFolder_samples ' exists already!!! Contents will possibly be overwritten'])
    end
    
    DesignFilesFolder_Outcomes=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,DataB.ID{Isub},'Outcomes');
    if  ~exist(DesignFilesFolder_Outcomes,'file')
        disp(['making folder ' DesignFilesFolder_Outcomes ' as it does not exist'])
        mkdir(DesignFilesFolder_Outcomes);
    else
        disp([DesignFilesFolder_Outcomes ' exists already!!! Contents will possibly be overwritten'])
    end
    %% Save regressors and contrast matrix in appropriate folders with names
    
    
    %Self Choices
    % First make one effect or phase onset regressor
    textfilecontent=[ChoiceSelfOnsets(IndexGLMSelfChoices) ChoiceSelfDurations(IndexGLMSelfChoices) ones(sum(IndexGLMSelfChoices),1)];
    dlmwrite(fullfile(DesignFilesFolder_selfChoices,'SelfChoiceMainEffect.txt'),textfilecontent,'delimiter', '\t');
    %Now make separate named file of each parametric regressor
    for l=1:length(LabelsDesignMatrixChoiceSelf)
        textfilecontent=[ChoiceSelfOnsets(IndexGLMSelfChoices) ChoiceSelfDurations(IndexGLMSelfChoices) DesignMatrixChoiceSelf(IndexGLMSelfChoices,l)];
        dlmwrite(fullfile(DesignFilesFolder_selfChoices,[LabelsDesignMatrixChoiceSelf{l} '.txt']),textfilecontent,'delimiter', '\t');
    end
    
    %Other Choices
    % First make one effect or phase onset regressor
    textfilecontent=[ChoiceOtherOnsets(IndexGLMOtherChoices) ChoiceOtherDurations(IndexGLMOtherChoices) ones(sum(IndexGLMOtherChoices),1)];
    dlmwrite(fullfile(DesignFilesFolder_otherChoices,'OtherChoiceMainEffect.txt'),textfilecontent,'delimiter', '\t');
    %Now make separate named file of each parametric regressor
    for l=1:length(LabelsDesignMatrixChoiceOther)
        textfilecontent=[ChoiceOtherOnsets(IndexGLMOtherChoices) ChoiceOtherDurations(IndexGLMOtherChoices) DesignMatrixChoiceOther(IndexGLMOtherChoices,l)];
        dlmwrite(fullfile(DesignFilesFolder_otherChoices,[LabelsDesignMatrixChoiceOther{l} '.txt']),textfilecontent,'delimiter', '\t');
    end
    
    %Sampling
    % First make one effect or phase onset regressor
    textfilecontent=[SamplingOnsets(IndexGLMSamples) SamplingDurations(IndexGLMSamples) ones(sum(IndexGLMSamples),1)];
    dlmwrite(fullfile(DesignFilesFolder_samples,'SamplesMainEffect.txt'),textfilecontent,'delimiter', '\t');
    %Now make separate named file of each parametric regressor
    for l=1:length(LabelsDesignMatrixSampling)
        textfilecontent=[SamplingOnsets(IndexGLMSamples) SamplingDurations(IndexGLMSamples) DesignMatrixSampling(IndexGLMSamples,l)];
        dlmwrite(fullfile(DesignFilesFolder_samples,[LabelsDesignMatrixSampling{l} '.txt']),textfilecontent,'delimiter', '\t');
    end
    
    %Outcomes
    % First make one effect or phase onset regressor
    textfilecontent=[OutcomeOnsets(IndexGLMOutcome) OutcomeDurations(IndexGLMOutcome) ones(sum(IndexGLMOutcome),1)];
    dlmwrite(fullfile(DesignFilesFolder_Outcomes,'OutcomeMainEffect.txt'),textfilecontent,'delimiter', '\t');
    %Now make separate named file of each parametric regressor
    for l=1:length(LabelsDesignMatrixOutcome)
        textfilecontent=[OutcomeOnsets(IndexGLMOutcome) OutcomeDurations(IndexGLMOutcome) DesignMatrixOutcome(IndexGLMOutcome,l)];
        dlmwrite(fullfile(DesignFilesFolder_Outcomes,[LabelsDesignMatrixOutcome{l} '.txt']),textfilecontent,'delimiter', '\t');
    end
    
    
    %Save information for timecourse analyses
    GLMout.fMRIGLM_info=fMRIGLM_info;
    %fMRIGLM_info.fMRIDesignName
    GLMout.SelfDec.Labels=LabelsDesignMatrixChoiceSelf;
    GLMout.SelfDec.DesignMatrix{Isub}=DesignMatrixChoiceSelf;
    GLMout.SelfDec.Onsets{Isub}=ChoiceSelfOnsets;
    GLMout.SelfDec.Durations{Isub}=ChoiceSelfDurations;
    GLMout.SelfDec.Index{Isub}=IndexGLMSelfChoices;
    
    GLMout.OtherDec.Labels=LabelsDesignMatrixChoiceOther;
    GLMout.OtherDec.DesignMatrix{Isub}=DesignMatrixChoiceOther;
    GLMout.OtherDec.Onsets{Isub}=ChoiceOtherOnsets;
    GLMout.OtherDec.Durations{Isub}=ChoiceOtherDurations;
    GLMout.OtherDec.Index{Isub}=IndexGLMOtherChoices;
    
    
    GLMout.Sampling.Labels=LabelsDesignMatrixSampling;
    GLMout.Sampling.DesignMatrix{Isub}=DesignMatrixSampling;
    GLMout.Sampling.Onsets{Isub}=SamplingOnsets;
    GLMout.Sampling.Durations{Isub}=SamplingDurations;
    GLMout.Sampling.Index{Isub}=IndexGLMSamples;
    
    GLMout.Outcome.Labels=LabelsDesignMatrixOutcome;
    GLMout.Outcome.DesignMatrix{Isub}=DesignMatrixOutcome;
    GLMout.Outcome.Onsets{Isub}=OutcomeOnsets;
    GLMout.Outcome.Durations{Isub}=OutcomeDurations;
    GLMout.Outcome.Index{Isub}=IndexGLMOutcome;
    
end

% Design Matrix and Design labels
dlmwrite(fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,'ContrastMatrix.txt'),ContrastWeights);
%because nothing can be easy and cells can't be dlm written another
%piece of code that does the same
CLabelsFilepath=fullfile(DataB.Basepath,'SEADesigns','fMRIGLMs',fMRIGLM_info.fMRIDesignName,'ContrastLabels.txt');
fid=fopen(CLabelsFilepath,'wt');
[rows,cols]=size(ContrastLabels);
for i=1:rows
    fprintf(fid,'%s',ContrastLabels{i}(1:end-1))
    fprintf(fid,'%s\n',ContrastLabels{i}(end))
end
fclose(fid);

%keyboard;
plotfMRIDesignCorrelations(DesignCorrelationsChoiceSelf,LabelsDesignMatrixChoiceSelf,'EventSelfChoices')
plotfMRIDesignCorrelations(DesignCorrelationsChoiceOther,LabelsDesignMatrixChoiceOther,'EventOtherChoices')
plotfMRIDesignCorrelations(DesignCorrelationsSampling,LabelsDesignMatrixSampling,'EventSampling')
plotfMRIDesignCorrelations(DesignCorrelationsOutcome,LabelsDesignMatrixOutcome,'EventOutcomes')

GLMout.AllConstrasts.Labels=ContrastLabels;
GLMout.AllConstrasts.Weights=ContrastWeights;


















