% 1 = TrialNum	
% 2 = CurrentRoundLeft	
% 3 = CurrentRoundRight	
% 4 = RewardLeft	
% 5 = RewardRight	
% 6 = RoundColor	
% 7 = RoundConditionLeft	
% 8 = RoundConditionRight	
% 9 = SlotChoice	
% 10 = GambsChooseLeft
% 11 = ProbeCondition
% 12 = Demographics
% 13 = RT
%%


%% new data
% 1 = participantSessionId	    -probably don't need, can put at the end
% 2 = participantNum	        -this will be come the file name, won't
% 3 = roundNum	                -index 1
% 4 = payoffCons	            -payoff consensus level: 0 = dissent, 1 =partial consensus, 2 = full consensus (treat 1 and 2 as same I think
% 5 = choice	                -what do you think
% 6 = groupFullCons	
% 7 = rewardWin	
% 8 = condition	
% 9 = rewardLeft	
% 10 = rewardRight	
% 11 = imageLeft	
% 12 = imageRight	
% 13 = ProbeType	
% 14 = colors

% loop through subjects, for each sub, what we care about most is probe trials: 
% wanna know when they have same shape and diff colors, those colors correspond to these 4 conditions: 
% how often did they pick the color that corresponds to each condition 
% (count number of times each condition was chosen) put that in matrix, take mean across subjects
clear
clc

d=dir('*.csv');


for s=1:length({d.name}) % for each file/subject
    format longg
    dat = readmatrix(d(s).name);
    d(s).name
    % get matrix info for current (s) subject
    condOneChoseCount = 0;
    condTwoChoseCount = 0;
    condThreeChoseCount = 0;
    condFourChoseCount = 0;
    condOneCount = 0;
    condTwoCount = 0;
    condThreeCount = 0;
    condFourCount = 0;

    %condOneChoseCountIcon1 = 0;
    %condTwoChoseCountIcon1 = 0;
    %condThreeChoseCountIcon1 = 0;
    %condFourChoseCountIcon1 = 0;
    condOneCountIcon1 = 0;
    condTwoCountIcon1 = 0;
    condThreeCountIcon1 = 0;
    condFourCountIcon1 = 0;

    %condOneChoseCountIcon2 = 0;
    %condTwoChoseCountIcon2 = 0;
    %condThreeChoseCountIcon2 = 0;
    %condFourChoseCountIcon2 = 0;
    condOneCountIcon2 = 0;
    condTwoCountIcon2 = 0;
    condThreeCountIcon2 = 0;
    condFourCountIcon2 = 0;

    %condOneChoseCountIcon3 = 0;
    %condTwoChoseCountIcon3 = 0;
    %condThreeChoseCountIcon3 = 0;
    %condFourChoseCountIcon3 = 0;
    condOneCountIcon3 = 0;
    condTwoCountIcon3 = 0;
    condThreeCountIcon3 = 0;
    condFourCountIcon3 = 0;

   
    condOneCountIcon4 = 0;
    condTwoCountIcon4 = 0;
    condThreeCountIcon4 = 0;
    condFourCountIcon4 = 0;

    highCount = 0;
    lowCount = 0; %4,5

    probeTrialZeroCount = 0;
    probeTrialOneCount = 0;
    probeTrialTwoCount = 0;

    probeTrialZeroIcon0Count = 0;
    probeTrialZeroIcon1Count = 0;
    probeTrialZeroIcon2Count = 0;
    probeTrialZeroIcon3Count = 0;
    probeTrialOneIcon0Count = 0;
    probeTrialOneIcon1Count = 0;
    probeTrialOneIcon2Count = 0;
    probeTrialOneIcon3Count = 0;
    condOneChoseIcon0Count = 0;
    condOneChoseIcon1Count = 0;
    condOneChoseIcon2Count = 0;
    condOneChoseIcon3Count = 0;
    condTwoChoseIcon0Count = 0;
    condTwoChoseIcon1Count = 0;
    condTwoChoseIcon2Count = 0;
    condTwoChoseIcon3Count = 0;
    condThreeChoseIcon0Count = 0;
    condThreeChoseIcon1Count = 0;
    condThreeChoseIcon2Count = 0;
    condThreeChoseIcon3Count = 0;
    condFourChoseIcon0Count = 0;
    condFourChoseIcon1Count = 0;
    condFourChoseIcon2Count = 0;
    condFourChoseIcon3Count = 0;



    roundCondition = 0;
    currentRound = 0;
    conditionChoice = 0;
    iconChoice = 0;
    rewChoice = 0;
    iconOppChoice = 0;

    meanRew1Count = 0;
    meanRew2Count = 0;
    meanRew3Count = 0;
    meanRew4Count = 0;

    meanRew1Cond1Count = 0;
    meanRew1Cond2Count = 0;
    meanRew1Cond3Count = 0;
    meanRew1Cond4Count = 0;

    meanRew2Cond1Count = 0;
    meanRew2Cond2Count = 0;
    meanRew2Cond3Count = 0;
    meanRew2Cond4Count = 0;

    meanRew3Cond1Count = 0;
    meanRew3Cond2Count = 0;
    meanRew3Cond3Count = 0;
    meanRew3Cond4Count = 0;
    meanRew3Cond4LeftCount = 0;
    meanRew3Cond4RightCount = 0;

    meanRew4Cond1Count = 0;
    meanRew4Cond2Count = 0;
    meanRew4Cond3Count = 0;
    meanRew4Cond4Count = 0;



    meanRew1Cond1 = 0;
    meanRew1Cond2 = 0;
    meanRew1Cond3 = 0;
    meanRew1Cond4 = 0;

    meanRew2Cond1 = 0;
    meanRew2Cond2 = 0;
    meanRew2Cond3 = 0;
    meanRew2Cond4 = 0;

    meanRew3Cond1 = 0;
    meanRew3Cond2 = 0;
    meanRew3Cond3 = 0;

    meanRew4Cond1 = 0;
    meanRew4Cond2 = 0;
    meanRew4Cond3 = 0;
    meanRew4Cond4 = 0;


    
%     condOneChange = zeros(16, 1, s);
%     condTwoChange = zeros(16, 1, s);
%     condThreeChange = zeros(16, 1, s);
%     condFourChange = zeros(16, 1, s);
    
    ratingsMat(24, 1) = NaN;
    q = 1;

    % do for loop through each trial
    
    % need to get delta for each condition in probe trials
    for i = 1:height(dat)
        
        if dat(i, 11) > -1 % if probe trial

            % new stuff:
            % For each consensus/win (color) condition, 
            % plot separately for high and low reward shapes
            % so, there will be 4 plots for each condition, resulting in 16
            % plots. first step: get conditions. Then, get id of icon
            % present (this will be different for probe type 2, it'll be
            % the opposite where we get the 1 condition, and get the 2 ids
            % of icons
            % we already have these variables: roundConditionLeft,
            % roundConditionRight, but need roundIconID.
            % then, once we get these variables for the current trial,
            % determine the mean (just as we did for the condition means)
            % but for each icon. so now each condition mean is going to
            % have 4 different means, one for each icon

            % problem: currently, im iterating at each condition both the
            % counter and the 'chose' counter, so they're all 100%
            % need to figure out how to iterate and get proper proportions

            %there are 12 probe trials for each type (12 for type 0, 12 for
            %type 1). that means that there are 12 opportunities for each
            %condition to be picked. out of those 12, must determine 1.)
            %how many times did each icon get displayed, and 2.) how many
            %times did that icon get chosen
         
            
            
            slotChoice = dat(i, 9); % get slot choice (37 or 39)
            if dat(i, 11) == 0 % if current trials probe type is 0 
                roundIconIDLeft = dat(i, 2)
                roundIconIDRight = dat(i, 3)


                probeTrialZeroCount =  probeTrialZeroCount + 1; % increment # of probe trial 0's by 1
                % going to be array [l, r]
                roundConditionLeft = dat(i, 7);
                roundConditionRight = dat(i, 8);
                if slotChoice == 37
                    conditionChoice = roundConditionLeft;
                elseif slotChoice == 39
                    conditionChoice = roundConditionRight;
                end
               
                if conditionChoice == 1 % if subject chose condition 1 when given option b/t 1 and 3
                    condOneChoseCount = condOneChoseCount + 1;
                    condOneCount = condOneCount + 1;
                    

 

                    % plot icon/condition choices
                    if roundIconIDLeft == 0
                        %condOneChoseCountIcon1 = condOneChoseCountIcon1 + 1
                        condOneCountIcon1 = condOneCountIcon1 + 1
                
                        probeTrialZeroIcon0Count = probeTrialZeroIcon0Count + 1
                        condOneChoseIcon0Count = condOneChoseIcon0Count + 1
                        

                    elseif roundIconIDLeft == 1
                        %condOneChoseCountIcon2 = condOneChoseCountIcon2 + 1
                        condOneCountIcon2 = condOneCountIcon2 + 1

                        probeTrialZeroIcon1Count = probeTrialZeroIcon1Count + 1
                        condOneChoseIcon1Count = condOneChoseIcon1Count + 1
                        
                    elseif roundIconIDLeft == 2
                        %condOneChoseCountIcon3 = condOneChoseCountIcon3 + 1
                        condOneCountIcon3 = condOneCountIcon3 + 1

                        probeTrialZeroIcon2Count = probeTrialZeroIcon2Count + 1
                        condOneChoseIcon2Count = condOneChoseIcon2Count + 1
                        % condOneChoseIcon2Count/probeTrialZeroIcon2Count;
                        

                    elseif roundIconIDLeft == 3
                        %condOneChoseCountIcon4 = condOneChoseCountIcon4 + 1
                        condOneCountIcon4 = condOneCountIcon4 + 1


                        probeTrialZeroIcon3Count = probeTrialZeroIcon3Count + 1
                        condOneChoseIcon3Count = condOneChoseIcon3Count + 1
                        
                    end

                elseif conditionChoice == 3
                    condThreeChoseCount = condThreeChoseCount + 1;
                    
                    condThreeCount = condThreeCount + 1;

                    % plot icon/condition choices
                    if roundIconIDLeft == 0
                        %condThreeChoseCountIcon1 = condThreeChoseCountIcon1 + 1
                        condThreeCountIcon1 = condThreeCountIcon1 + 1

                        probeTrialZeroIcon0Count = probeTrialZeroIcon0Count + 1
                        condThreeChoseIcon0Count = condThreeChoseIcon0Count + 1

                        
                    elseif roundIconIDLeft == 1
                        %condThreeChoseCountIcon2 = condThreeChoseCountIcon2 + 1
                        condThreeCountIcon2 = condThreeCountIcon2 + 1

                        probeTrialZeroIcon1Count = probeTrialZeroIcon1Count + 1
                        condThreeChoseIcon1Count = condThreeChoseIcon1Count + 1

                    elseif roundIconIDLeft == 2
                        %condThreeChoseCountIcon3 = condThreeChoseCountIcon3 + 1
                        condThreeCountIcon3 = condThreeCountIcon3 + 1

                        probeTrialZeroIcon2Count = probeTrialZeroIcon2Count + 1
                        condThreeChoseIcon2Count = condThreeChoseIcon2Count + 1
                    elseif roundIconIDLeft == 3
                        %condThreeChoseCountIcon4 = condThreeChoseCountIcon4 + 1
                        condThreeCountIcon4 = condThreeCountIcon4 + 1

                        probeTrialZeroIcon3Count = probeTrialZeroIcon3Count + 1
                        condThreeChoseIcon3Count = condThreeChoseIcon3Count + 1
                    end
                end

       
                


                condOneChange(probeTrialZeroCount,1,s) = condOneChoseCount/probeTrialZeroCount;
                condThreeChange(probeTrialZeroCount,1,s) = condThreeChoseCount/probeTrialZeroCount;

            elseif dat(i, 11) == 1
                roundIconIDLeft = dat(i, 2)
                roundIconIDRight = dat(i, 3)


                probeTrialOneCount =  probeTrialOneCount + 1;
                roundConditionLeft = dat(i, 7);
                roundConditionRight = dat(i, 8);
                if slotChoice == 37
                    conditionChoice = roundConditionLeft;
                elseif slotChoice == 39
                    conditionChoice = roundConditionRight;
                end
                if conditionChoice == 2
                    
                    condTwoChoseCount = condTwoChoseCount + 1;
                    condTwoCount = condTwoCount + 1;
                    


                    

                    % plot icon/condition choices
                    if roundIconIDLeft == 0
                        %condTwoChoseCountIcon1 = condTwoChoseCountIcon1 + 1
                        condTwoCountIcon1 = condTwoCountIcon1 + 1

                        probeTrialOneIcon0Count = probeTrialOneIcon0Count + 1
                        condTwoChoseIcon0Count = condTwoChoseIcon0Count + 1
                    elseif roundIconIDLeft == 1
                        %condTwoChoseCountIcon2 = condTwoChoseCountIcon2 + 1
                        condTwoCountIcon2 = condTwoCountIcon2 + 1

                        probeTrialOneIcon1Count = probeTrialOneIcon1Count + 1
                        condTwoChoseIcon1Count = condTwoChoseIcon1Count + 1
                    elseif roundIconIDLeft == 2
                        %condTwoChoseCountIcon3 = condTwoChoseCountIcon3 + 1
                        condTwoCountIcon3 = condTwoCountIcon3 + 1

                        probeTrialOneIcon2Count = probeTrialOneIcon2Count + 1
                        condTwoChoseIcon2Count = condTwoChoseIcon2Count + 1
                    elseif roundIconIDLeft == 3
                        %condTwoChoseCountIcon4 = condTwoChoseCountIcon4 + 1
                        condTwoCountIcon4 = condTwoCountIcon4 + 1

                        probeTrialOneIcon3Count = probeTrialOneIcon3Count + 1
                        condTwoChoseIcon3Count = condTwoChoseIcon3Count + 1
                    end

                elseif conditionChoice == 4
                   
                    condFourChoseCount = condFourChoseCount + 1;
                    
                    condFourCount = condFourCount + 1;

                    % plot icon/condition choices
                    if roundIconIDLeft == 0
                        %condFourChoseCountIcon1 = condFourChoseCountIcon1 + 1
                        condFourCountIcon1 = condFourCountIcon1 + 1

                        probeTrialOneIcon0Count = probeTrialOneIcon0Count + 1
                        condFourChoseIcon0Count = condFourChoseIcon0Count + 1
                    elseif roundIconIDLeft == 1
                        %condFourChoseCountIcon2 = condFourChoseCountIcon2 + 1
                        condFourCountIcon2 = condFourCountIcon2 + 1

                        probeTrialOneIcon1Count = probeTrialOneIcon1Count + 1
                        condFourChoseIcon1Count = condFourChoseIcon1Count + 1
                    elseif roundIconIDLeft == 2
                        %condFourChoseCountIcon3 = condFourChoseCountIcon3 + 1
                        condFourCountIcon3 = condFourCountIcon3 + 1

                        probeTrialOneIcon2Count = probeTrialOneIcon2Count + 1
                        condFourChoseIcon2Count = condFourChoseIcon2Count + 1
                    elseif roundIconIDLeft == 3
                        %condFourChoseCountIcon4 = condFourChoseCountIcon4 + 1
                        condFourCountIcon4 = condFourCountIcon4 + 1

                        probeTrialOneIcon3Count = probeTrialOneIcon3Count + 1
                        condFourChoseIcon3Count = condFourChoseIcon3Count + 1
                    end

                end
                condTwoChange(probeTrialOneCount,1,s) = condTwoChoseCount/probeTrialOneCount;
                condFourChange(probeTrialOneCount,1,s) = condFourChoseCount/probeTrialOneCount;
            
            elseif dat(i, 11) == 2 % if current trials probe type is 2
                roundIconIDLeft = dat(i, 2)
                roundIconIDRight = dat(i, 3)


                probeTrialTwoCount = probeTrialTwoCount + 1;
                roundCondition = dat(i, 8);
                roundConditionLeft = dat(i, 7)
                roundConditionRight = dat(i, 8)
                currentRoundLeft = dat(i, 2);
                currentRoundRight = dat(i, 3);

                

                if slotChoice == 37
                    iconChoice = currentRoundLeft;
                    iconOppChoice = currentRoundRight;
                elseif slotChoice == 39
                    iconChoice = currentRoundRight;
                    iconOppChoice = currentRoundLeft;
                end
                if iconChoice < iconOppChoice % if choice is 0 or 1 (high)
                    highCount = highCount + 1;
                elseif iconChoice > iconOppChoice % if choice is 4 or 5 (low
                    lowCount = lowCount + 1;
                end
                % check variables for condition
                % increment condition by 1
            end

        else % normal trial
            % get mean reward payout for each icon
            % icons are (i, 2) and (i, 3), rewards are (i, 4) and (i, 5)
            currIconLeft = dat(i, 2);
            currIconRight = dat(i, 3);
            currRewLeft = dat(i, 4);
            currRewRight = dat(i, 5);
            currCondition = dat(i, 7);
            slotChoice = dat(i, 9);

            %left rew
            if currIconLeft == 0 % icon 1
                % do some operation to add this value to current array and
                % then compute mean (or add to array and compute mean at
                % the end of the loop)
                meanRew1Count = meanRew1Count + 1;
                meanRew1(meanRew1Count)  = currRewLeft;
            elseif currIconLeft == 1 % icon 2
                meanRew2Count = meanRew2Count + 1;
                meanRew2(meanRew2Count)  = currRewLeft;
            elseif currIconLeft == 2 % icon 3
                meanRew3Count = meanRew3Count + 1;
                meanRew3(meanRew3Count)  = currRewLeft;
            elseif currIconLeft == 3 % icon 4
                meanRew4Count = meanRew4Count + 1;
                meanRew4(meanRew4Count)  = currRewLeft;
            end

            %right rew
            if currIconRight == 0 % icon 1
                % do some operation to add this value to current array and
                % then compute mean (or add to array and compute mean at
                % the end of the loop)
                meanRew1Count = meanRew1Count + 1;
                meanRew1(meanRew1Count)  = currRewRight;
            elseif currIconRight == 1 % icon 2
                meanRew2Count = meanRew2Count + 1;
                meanRew2(meanRew2Count)  = currRewRight;
            elseif currIconRight == 2 % icon 3
                meanRew3Count = meanRew3Count + 1;
                meanRew3(meanRew3Count)  = currRewRight;
            elseif currIconRight == 3 % icon 4
                meanRew4Count = meanRew4Count + 1;
                meanRew4(meanRew4Count)  = currRewRight;
            end


            %get rew for each condition
            if currCondition == 1
                if slotChoice == 37
                    if currIconLeft == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond1Count = meanRew1Cond1Count + 1;
                        meanRew1Cond1(meanRew1Cond1Count)  = currRewLeft;
                    elseif currIconLeft == 1 % icon 2
                        meanRew2Cond1Count = meanRew2Cond1Count + 1;
                        meanRew2Cond1(meanRew2Cond1Count)  = currRewLeft;
                    elseif currIconLeft == 2 % icon 3
                        meanRew3Cond1Count = meanRew3Cond1Count + 1;
                        meanRew3Cond1(meanRew3Cond1Count)  = currRewLeft;
                    elseif currIconLeft == 3 % icon 4
                        meanRew4Cond1Count = meanRew4Cond1Count + 1;
                        meanRew4Cond1(meanRew4Cond1Count)  = currRewLeft;
                    end
                elseif slotChoice == 39
                    %right rew
                    if currIconRight == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond1Count = meanRew1Cond1Count + 1;
                        meanRew1Cond1(meanRew1Cond1Count)  = currRewRight;
                    elseif currIconRight == 1 % icon 2
                        meanRew2Cond1Count = meanRew2Cond1Count + 1;
                        meanRew2Cond1(meanRew2Cond1Count)  = currRewRight;
                    elseif currIconRight == 2 % icon 3
                        meanRew3Cond1Count = meanRew3Cond1Count + 1;
                        meanRew3Cond1(meanRew3Cond1Count)  = currRewRight;
                    elseif currIconRight == 3 % icon 4
                        meanRew4Cond1Count = meanRew4Cond1Count + 1;
                        meanRew4Cond1(meanRew4Cond1Count)  = currRewRight;
                    end
                end

            elseif currCondition == 2
                if slotChoice == 37
                    if currIconLeft == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond2Count = meanRew1Cond2Count + 1;
                        meanRew1Cond2(meanRew1Cond2Count)  = currRewLeft;
                    elseif currIconLeft == 1 % icon 2
                        meanRew2Cond2Count = meanRew2Cond2Count + 1;
                        meanRew2Cond2(meanRew2Cond2Count)  = currRewLeft;
                    elseif currIconLeft == 2 % icon 3
                        meanRew3Cond2Count = meanRew3Cond2Count + 1;
                        meanRew3Cond2(meanRew3Cond2Count)  = currRewLeft;
                    elseif currIconLeft == 3 % icon 4
                        meanRew4Cond2Count = meanRew4Cond2Count + 1;
                        meanRew4Cond2(meanRew4Cond2Count)  = currRewLeft;
                    end
                elseif slotChoice == 39
                    %right rew
                    if currIconRight == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond2Count = meanRew1Cond2Count + 1;
                        meanRew1Cond2(meanRew1Cond2Count)  = currRewRight;
                    elseif currIconRight == 1 % icon 2
                        meanRew2Cond2Count = meanRew2Cond2Count + 1;
                        meanRew2Cond2(meanRew2Cond2Count)  = currRewRight;
                    elseif currIconRight == 2 % icon 3
                        meanRew3Cond2Count = meanRew3Cond2Count + 1;
                        meanRew3Cond2(meanRew3Cond2Count)  = currRewRight;
                    elseif currIconRight == 3 % icon 4
                        meanRew4Cond2Count = meanRew4Cond2Count + 1;
                        meanRew4Cond2(meanRew4Cond2Count)  = currRewRight;
                    end
                end

            elseif currCondition == 3
                if slotChoice == 37
                    if currIconLeft == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond3Count = meanRew1Cond3Count + 1;
                        meanRew1Cond3(meanRew1Cond3Count)  = currRewLeft;
                    elseif currIconLeft == 1 % icon 2
                        meanRew2Cond3Count = meanRew2Cond3Count + 1;
                        meanRew2Cond3(meanRew2Cond3Count)  = currRewLeft;
                    elseif currIconLeft == 2 % icon 3
                        meanRew3Cond3Count = meanRew3Cond3Count + 1;
                        meanRew3Cond3(meanRew3Cond3Count)  = currRewLeft;
                    elseif currIconLeft == 3 % icon 4
                        meanRew4Cond3Count = meanRew4Cond3Count + 1;
                        meanRew4Cond3(meanRew4Cond3Count)  = currRewLeft;
                    end
                elseif slotChoice == 39
                    %right rew
                    if currIconRight == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond3Count = meanRew1Cond3Count + 1;
                        meanRew1Cond3(meanRew1Cond3Count)  = currRewRight;
                    elseif currIconRight == 1 % icon 2
                        meanRew2Cond3Count = meanRew2Cond3Count + 1;
                        meanRew2Cond3(meanRew2Cond3Count)  = currRewRight;
                    elseif currIconRight == 2 % icon 3
                        meanRew3Cond3Count = meanRew3Cond3Count + 1;
                        meanRew3Cond3(meanRew3Cond3Count)  = currRewRight;
                        % they never chose 2 here, so there is nothing in
                        % 'if currIconRight == 2'
                    

                        %meanRew3Cond3Count(isnan(meanRew3Cond3Count)) = 0;
                        %meanRew3Cond3(isnan(meanRew3Cond3)) = 0;
                        
                    elseif currIconRight == 3 % icon 4
                        meanRew4Cond3Count = meanRew4Cond3Count + 1;
                        meanRew4Cond3(meanRew4Cond3Count)  = currRewRight;
                    end
                end

            elseif currCondition == 4
                if slotChoice == 37
                    if currIconLeft == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond4Count = meanRew1Cond4Count + 1;
                        meanRew1Cond4(meanRew1Cond4Count)  = currRewLeft;
                    elseif currIconLeft == 1 % icon 2
                        meanRew2Cond4Count = meanRew2Cond4Count + 1;
                        meanRew2Cond4(meanRew2Cond4Count)  = currRewLeft;
                    elseif currIconLeft == 2 % icon 3
                        meanRew3Cond4LeftCount = meanRew3Cond4LeftCount + 1
                        meanRew3Cond4Count = meanRew3Cond4Count + 1;
                        meanRew3Cond4(meanRew3Cond4Count)  = currRewLeft;
                    elseif currIconLeft == 3 % icon 4
                        meanRew4Cond4Count = meanRew4Cond4Count + 1;
                        meanRew4Cond4(meanRew4Cond4Count)  = currRewLeft;
                    end
                elseif slotChoice == 39
                    %right rew
                    if currIconRight == 0 % icon 1
                        % do some operation to add this value to current array and
                        % then compute mean (or add to array and compute mean at
                        % the end of the loop)
                        meanRew1Cond4Count = meanRew1Cond4Count + 1;
                        meanRew1Cond4(meanRew1Cond4Count)  = currRewRight;
                    elseif currIconRight == 1 % icon 2
                        meanRew2Cond4Count = meanRew2Cond4Count + 1;
                        meanRew2Cond4(meanRew2Cond4Count)  = currRewRight;
                    elseif currIconRight == 2 % icon 3
                        meanRew3Cond4RightCount = meanRew3Cond4RightCount + 1
                        meanRew3Cond4Count = meanRew3Cond4Count + 1;
                        meanRew3Cond4(meanRew3Cond4Count)  = currRewRight;
                    elseif currIconRight == 3 % icon 4
                        meanRew4Cond4Count = meanRew4Cond4Count + 1;
                        meanRew4Cond4(meanRew4Cond4Count)  = currRewRight;
                    end
                end

            end



        end
        
    
        if dat(i, 12) > -1
            p = i+4;
            ratingsMatPre(q, 1, s) = dat(i, 12);
            ratingsMat(q, 1, s) = dat(i, 12) - dat(p, 13); 
            ratingsMatPost(q, 1, s) = dat(p, 13);
            q = q+1;
        end
        
        % put variables in matrix
        
    end
    condOneProportion(s) = condOneCount/probeTrialZeroCount;
    condTwoProportion(s) = condTwoCount/probeTrialOneCount;
    condThreeProportion(s) = condThreeCount/probeTrialZeroCount;
    condFourProportion(s) = condFourCount/probeTrialOneCount;
    
    condOneIcon0Proportion(s) = condOneChoseIcon0Count/probeTrialZeroIcon0Count;
    condOneIcon1Proportion(s) = condOneChoseIcon1Count/probeTrialZeroIcon1Count;
    condOneIcon2Proportion(s) = condOneChoseIcon2Count/probeTrialZeroIcon2Count;
    condOneIcon2Proportion(isnan(condOneIcon2Proportion))=0;
    condOneIcon3Proportion(s) = condOneChoseIcon3Count/probeTrialZeroIcon3Count;

    condTwoIcon0Proportion(s) = condTwoChoseIcon0Count/probeTrialOneIcon0Count;
    condTwoIcon1Proportion(s) = condTwoChoseIcon1Count/probeTrialOneIcon1Count;
    condTwoIcon2Proportion(s) = condTwoChoseIcon2Count/probeTrialOneIcon2Count;
    condTwoIcon3Proportion(s) = condTwoChoseIcon3Count/probeTrialOneIcon3Count;

    condThreeIcon0Proportion(s) = condThreeChoseIcon0Count/probeTrialZeroIcon0Count;
    condThreeIcon1Proportion(s) = condThreeChoseIcon1Count/probeTrialZeroIcon1Count;
    condThreeIcon2Proportion(s) = condThreeChoseIcon2Count/probeTrialZeroIcon2Count;
    condThreeIcon2Proportion(isnan(condThreeIcon2Proportion))=0;
    condThreeIcon3Proportion(s) = condThreeChoseIcon3Count/probeTrialZeroIcon3Count;

    condFourIcon0Proportion(s) = condFourChoseIcon0Count/probeTrialOneIcon0Count;
    condFourIcon1Proportion(s) = condFourChoseIcon1Count/probeTrialOneIcon1Count;
    condFourIcon2Proportion(s) = condFourChoseIcon2Count/probeTrialOneIcon2Count;
    condFourIcon3Proportion(s) = condFourChoseIcon3Count/probeTrialOneIcon3Count;



    iconChoiceHighProportion(s) = highCount/probeTrialTwoCount;
    iconChoiceLowProportion(s) = lowCount/probeTrialTwoCount;

    reward1(s) = sum(meanRew1)/meanRew1Count;
    reward2(s) = sum(meanRew2)/meanRew2Count;
    reward3(s) = sum(meanRew3)/meanRew3Count;
    reward4(s) = sum(meanRew4)/meanRew4Count;

    reward1Cond1(s) = sum(meanRew1Cond1)/meanRew1Cond1Count;
    reward2Cond1(s) = sum(meanRew2Cond1)/meanRew2Cond1Count;
    reward3Cond1(s) = sum(meanRew3Cond1)/meanRew3Cond1Count;
    reward4Cond1(s) = sum(meanRew4Cond1)/meanRew4Cond1Count;

    reward1Cond2(s) = sum(meanRew1Cond2)/meanRew1Cond2Count;
    reward2Cond2(s) = sum(meanRew2Cond2)/meanRew2Cond2Count;
    reward3Cond2(s) = sum(meanRew3Cond2)/meanRew3Cond2Count;
    reward4Cond2(s) = sum(meanRew4Cond2)/meanRew4Cond2Count;

    reward1Cond3(s) = sum(meanRew1Cond3)/meanRew1Cond3Count;
    reward2Cond3(s) = sum(meanRew2Cond3)/meanRew2Cond3Count;
    reward3Cond3(s) = sum(meanRew3Cond3)/meanRew3Cond3Count
    %reward3Cond3(isnan(reward3Cond3)) = 0;
    reward4Cond3(s) = sum(meanRew4Cond3)/meanRew4Cond3Count;

    reward1Cond4(s) = sum(meanRew1Cond4)/meanRew1Cond4Count;
    reward2Cond4(s) = sum(meanRew2Cond4)/meanRew2Cond4Count;
    reward3Cond4(s) = sum(meanRew3Cond4)/meanRew3Cond4Count;
    reward4Cond4(s) = sum(meanRew4Cond4)/meanRew4Cond4Count;

    meanReward1 = mean(reward1);
    meanReward2 = mean(reward2);
    meanReward3 = mean(reward3);
    meanReward4 = mean(reward4);

    meanReward1Cond1 = mean(reward1Cond1);
    meanReward2Cond1 = mean(reward2Cond1);
    meanReward3Cond1 = mean(reward3Cond1);
    meanReward4Cond1 = mean(reward4Cond1);
    meanRewardsCond1 = [meanReward1Cond1, meanReward2Cond1, meanReward3Cond1, meanReward4Cond1]

    meanReward1Cond2 = mean(reward1Cond2);
    meanReward2Cond2 = mean(reward2Cond2);
    meanReward3Cond2 = mean(reward3Cond2);
    meanReward4Cond2 = mean(reward4Cond2);
    meanRewardsCond2 = [meanReward1Cond2, meanReward2Cond2, meanReward3Cond2, meanReward4Cond2]

    meanReward1Cond3 = mean(reward1Cond3);
    meanReward2Cond3 = mean(reward2Cond3);
    %meanReward3Cond3 = mean(reward3Cond3);
    meanReward3Cond3 = mean(reward3Cond3, 'omitnan');
    meanReward4Cond3 = mean(reward4Cond3);
    meanRewardsCond3 = [meanReward1Cond3, meanReward2Cond3, meanReward3Cond3, meanReward4Cond3]

    meanReward1Cond4 = mean(reward1Cond4);
    meanReward2Cond4 = mean(reward2Cond4);
    meanReward3Cond4 = mean(reward3Cond4);
    meanReward4Cond4 = mean(reward4Cond4);
    meanRewardsCond4 = [meanReward1Cond4, meanReward2Cond4, meanReward3Cond4, meanReward4Cond4]

    
    
    %attempting to make 6x4xs matrix, rows: image, cols: condition, z: sub
    
%     ratings(1, :, s) = ratingsMat((1:4), 1, s)
%     ratings(2, :, s) = ratingsMat((5:8), 1, s);
%     ratings(3, :, s) = ratingsMat((9:12), 1, s);
%     ratings(4, :, s) = ratingsMat((13:16), 1, s);
%     ratings(5, :, s) = ratingsMat((17:20), 1, s);
%     ratings(6, :, s) = ratingsMat((21:24), 1, s);
    
    ratings(:, 1, s) = ratingsMat((1:4), 1, s)
    %ratings(:, 2, s) = ratingsMat((5:8), 1, s);
    %ratings(:, 3, s) = ratingsMat((9:12), 1, s);
    %ratings(:, 4, s) = ratingsMat((13:16), 1, s);
    %ratings(:, 5, s) = ratingsMat((17:20), 1, s);
    %ratings(:, 6, s) = ratingsMat((21:24), 1, s);

    %ratings = ratings';

    ratingsPre(:,1, s) = ratingsMatPre((1:4), 1, s);
    %ratingsPre(:,2, s) = ratingsMatPre((5:8), 1, s);
    %ratingsPre(:,3, s) = ratingsMatPre((9:12), 1, s);
    %ratingsPre(:,4, s) = ratingsMatPre((13:16), 1, s);
    %ratingsPre(:,5, s) = ratingsMatPre((17:20), 1, s);
    %ratingsPre(:,6, s) = ratingsMatPre((21:24), 1, s);

    %ratingsPre = ratingsPre';

    ratingsPost(:,1, s) = ratingsMatPost((1:4), 1, s);
   % ratingsPost(:,2, s) = ratingsMatPost((5:8), 1, s);
    %ratingsPost(:,3, s) = ratingsMatPost((9:12), 1, s);
    %ratingsPost(:,4, s) = ratingsMatPost((13:16), 1, s);
    %ratingsPost(:,5, s) = ratingsMatPost((17:20), 1, s);
    %ratingsPost(:,6, s) = ratingsMatPost((21:24), 1, s);

    %ratingsPost = ratingsPost';
    %rn, ratingsAvg is changing each trial based on subject. need for it to
    %average across s
    for i = 1:4
        ratingsAvg(1, i, s) = mean(ratings(i, :, s));
        ratingsAvgPre(1, i, s) = mean(ratingsPre(i, :, s))
        ratingsAvgPost(1, i, s) = mean(ratingsPost(i, :, s));
    end
    
end
for iii = 1:4
    ratingsAvgFinal(1,iii) = mean(ratingsAvg(1, iii, :))
    ratingsAvgPreFinal(1, iii) = mean(ratingsAvgPre(1, iii, :))
    ratingsAvgPostFinal(1, iii) = mean(ratingsAvgPost(1, iii, :))
end


meanOne = mean(condOneProportion, 'omitnan');
meanTwo = mean(condTwoProportion, 'omitnan');
meanThree = mean(condThreeProportion, 'omitnan');
meanFour = mean(condFourProportion, 'omitnan');

meanOneIcon1 = mean(condOneIcon0Proportion, "omitnan")
meanOneIcon2 = mean(condOneIcon1Proportion, "omitnan")
meanOneIcon3 = mean(condOneIcon2Proportion, "omitnan")
meanOneIcon4 = mean(condOneIcon3Proportion, "omitnan")

meanTwoIcon1 = mean(condTwoIcon0Proportion, "omitnan")
meanTwoIcon2 = mean(condTwoIcon1Proportion, "omitnan")
meanTwoIcon3 = mean(condTwoIcon2Proportion, "omitnan")
meanTwoIcon4 = mean(condTwoIcon3Proportion, "omitnan")

meanThreeIcon1 = mean(condThreeIcon0Proportion, "omitnan")
meanThreeIcon2 = mean(condThreeIcon1Proportion, "omitnan")
meanThreeIcon3 = mean(condThreeIcon2Proportion, "omitnan")
meanThreeIcon4 = mean(condThreeIcon3Proportion, "omitnan")

meanFourIcon1 = mean(condFourIcon0Proportion, "omitnan")
meanFourIcon2 = mean(condFourIcon1Proportion, "omitnan")
meanFourIcon3 = mean(condFourIcon2Proportion, "omitnan")
meanFourIcon4 = mean(condFourIcon3Proportion, "omitnan")

meanHighRew = sum(iconChoiceHighProportion)/s
meanLowRew = sum(iconChoiceLowProportion)/s


fprintf('------ Data ------\n\n');
fprintf('* Condition 1 Mean: ', d.name);
fprintf('%7.3f\n', meanOne);
fprintf('* Condition 2 Mean: ', d.name);
fprintf('%7.3f\n', meanTwo);
fprintf('* Condition 3 Mean: ', d.name);
fprintf('%7.3f\n', meanThree);
fprintf('* Condition 4 Mean: ', d.name);
fprintf('%7.3f\n', meanFour);
fprintf('* High Reward Choice Mean: ', d.name);
fprintf('%7.3f\n', meanHighRew);
fprintf('* Low Reward Choice Mean: ', d.name);
fprintf('%7.3f\n', meanLowRew);


iconValue = nan(276,6,5);
for ii = 1:length({d.name}) % for each subject
    data = readmatrix(d(ii).name);
    for jj=1:height(data) % for each trial
        if data(jj, 2) > -1
            if isnan(data(jj, 11)) % if normal trial
                if slotChoice == 37 % if chose left
                    iconID = data(jj, 2) + 1; % get id of icon (0-5) convert to matlab (1-6)
                    iconValue(jj, iconID, ii) = data(jj, 4);
                elseif slotChoice == 39
                    iconID = data(jj, 3) + 1;
                    iconValue(jj, iconID, ii) = data(jj, 5);
                end

            end
        end
        
    end
end

% for p = 1:length({d.name})
% 
% 
%     meanIconValues(p,1) = mean(iconValue(:,1,p), 'omitnan');
%     meanIconValues(p,2) = mean(iconValue(:,2,p), 'omitnan');
%     meanIconValues(p,3) = mean(iconValue(:,3,p), 'omitnan');
%     meanIconValues(p,4) = mean(iconValue(:,4,p), 'omitnan');
%     %meanIconValues(p,5) = mean(iconValue(:,5,p), 'omitnan');
%     %meanIconValues(p,6) = mean(iconValue(:,6,p), 'omitnan');
%     
% end



   


prePostRatingsMat = [ratingsAvgPreFinal; ratingsAvgPostFinal]