% This script uses EEG data in which all trials (segments) of all 
% participants is kept. Baseline correction, artifact rejection on
% eye-movements (EOG) and on individual channel mode have been performed.
% The data was also down-sampeled to 500Hz. All channels are also included.
% The script requires a data set in which eye-movements is marked instead 
% of removed. It first checks what segments are removed by looking for the
% marker 'Bad Interval', gives all segments a name corresponding to the
% item, and finally replaces the values in bad segments with NA values.
% Segments are then averaged (50:550, 0:50 is baseline) to do further
% trial-based analysis

% Matlab v.R2015b
%% Processing Object data

clear all

% Specify folder for Object data
cd Object\raw_data;

% Collect files and lists
files = dir('*with60segments.mat');
numberofdatasets = size(files,1);

lists = dir('.../lists/*.txt'); %Change accordingly

% Read in lists and their contents
list1 = readtable(lists(1).name);
list2 = readtable(lists(2).name);
list3 = readtable(lists(3).name);
list4 = readtable(lists(4).name);
list5 = readtable(lists(5).name);
list6 = readtable(lists(6).name);
list7 = readtable(lists(7).name);
list8 = readtable(lists(8).name);
list9 = readtable(lists(9).name);
list10 = readtable(lists(10).name);
list11 = readtable(lists(11).name);
list12 = readtable(lists(12).name);

% Make the brain regions
Lant = ["Fp1","AF7","AF3","F3","F5","F7"];
Lcent = ["FC5","FC3","C3","C5","CP5","CP3"];
Lpost = ["P3","P5","P7","PO7","PO3","O1"];
Rant = ["Fp2","AF8","AF4","F4","F6","F8"];
Rcent = ["FC6","FC4","C4","C6","CP6","CP4"];
Rpost = ["P4","P6","P8","PO8","PO4","O2"];
Cant = ["Fpz","AFz","Fz"];
Ccent = ["FCz","Cz","CPz"];
Cpost = ["Oz","POz","Pz"];

% Predefine variabeles
newstimfield = "stimuluslist";
numseg = zeros(1,1);
channels = zeros(64,1);
context = [1,1,0,0]';
lateralization = ["Left","Left","Left","Right","Right","Right","Center","Center","Center"]';
anteriority = ["Anterior","Central","Posterior"]';

region6elec = 6;
region3elec = 3;

brainregions = region3elec+region6elec;
pattern = '(ONLY(\d+)([A-Z]+)(\d+))';
    all_erptrialdata_100_200 = ["Participant","ERP","Item","Accent","Context","Lateralization","Anteriority","Group"];
    all_erptrialdata_200_390 = ["Participant","ERP","Item","Accent","Context","Lateralization","Anteriority","Group"];
    all_erptrialdata_500_900 = ["Participant","ERP","Item","Accent","Context","Lateralization","Anteriority","Group"];

    


% Loop through files
for file = files'
    % Clear variables
    clearvars -except files numberofdatasets lists list1 list2 list3 list4 list5 list6 list7 list8 list9 list10 list11 list12 Lant Rant Cant Lcent Rcent Ccent Lpost Rpost Cpost newstimfield numseg channels context lateralization anteriority region6elec region3elec brainregions pattern file all_erptrialdata_100_200 all_erptrialdata_200_390 all_erptrialdata_500_900


    % Load in one file. This is from 1 participant, from 1 word, in 1
    % condition.
    data = load(file.name, '-mat');
    
    % Count number of segments. This differs from 60 for some participant
    % due to technical difficulties that caused the experiment to stop too
    % early.
    numseg = data.SegmentCount;
    ERP = zeros(numseg*numberofdatasets*brainregions,1);
    
    % Make datavariables
    dataperchan_100_200_lant = zeros(numseg,region6elec);
    dataperchan_200_390_lant = zeros(numseg,region6elec);
    dataperchan_500_900_lant = zeros(numseg,region6elec);
    dataperchan_100_200_rant = zeros(numseg,region6elec);
    dataperchan_200_390_rant = zeros(numseg,region6elec);
    dataperchan_500_900_rant = zeros(numseg,region6elec);
    dataperchan_100_200_cant = zeros(numseg,region3elec);
    dataperchan_200_390_cant = zeros(numseg,region3elec);
    dataperchan_500_900_cant = zeros(numseg,region3elec);
    dataperchan_100_200_lcent = zeros(numseg,region6elec);
    dataperchan_200_390_lcent = zeros(numseg,region6elec);
    dataperchan_500_900_lcent = zeros(numseg,region6elec);
    dataperchan_100_200_rcent = zeros(numseg,region6elec);
    dataperchan_200_390_rcent = zeros(numseg,region6elec);
    dataperchan_500_900_rcent = zeros(numseg,region6elec);
    dataperchan_100_200_ccent = zeros(numseg,region3elec);
    dataperchan_200_390_ccent = zeros(numseg,region3elec);
    dataperchan_500_900_ccent = zeros(numseg,region3elec);
    dataperchan_100_200_lpost = zeros(numseg,region6elec);
    dataperchan_200_390_lpost = zeros(numseg,region6elec);
    dataperchan_500_900_lpost = zeros(numseg,region6elec);
    dataperchan_100_200_rpost = zeros(numseg,region6elec);
    dataperchan_200_390_rpost = zeros(numseg,region6elec);
    dataperchan_500_900_rpost = zeros(numseg,region6elec);
    dataperchan_100_200_cpost = zeros(numseg,region3elec);
    dataperchan_200_390_cpost = zeros(numseg,region3elec);
    dataperchan_500_900_cpost = zeros(numseg,region3elec);
    segdata_100_200_lant = zeros(numseg,1);
    segdata_200_390_lant = zeros(numseg,1);
    segdata_500_900_lant = zeros(numseg,1);
    segdata_100_200_rant = zeros(numseg,1);
    segdata_200_390_rant = zeros(numseg,1);
    segdata_500_900_rant = zeros(numseg,1);
    segdata_100_200_cant = zeros(numseg,1);
    segdata_200_390_cant = zeros(numseg,1);
    segdata_500_900_cant = zeros(numseg,1);
    segdata_100_200_lcent = zeros(numseg,1);
    segdata_200_390_lcent = zeros(numseg,1);
    segdata_500_900_lcent = zeros(numseg,1);
    segdata_100_200_rcent = zeros(numseg,1);
    segdata_200_390_rcent = zeros(numseg,1);
    segdata_500_900_rcent = zeros(numseg,1);
    segdata_100_200_ccent = zeros(numseg,1);
    segdata_200_390_ccent = zeros(numseg,1);
    segdata_500_900_ccent = zeros(numseg,1);
    segdata_100_200_lpost = zeros(numseg,1);
    segdata_200_390_lpost = zeros(numseg,1);
    segdata_500_900_lpost = zeros(numseg,1);
    segdata_100_200_rpost = zeros(numseg,1);
    segdata_200_390_rpost = zeros(numseg,1);
    segdata_500_900_rpost = zeros(numseg,1);
    segdata_100_200_cpost = zeros(numseg,1);
    segdata_200_390_cpost = zeros(numseg,1);
    segdata_500_900_cpost = zeros(numseg,1);
    
    
    % ARTIFACT REMOVAL OF SEGMENTS
    % The EOG and individual channel mode artifact rejection needs to be
    % done. All segments that were removed during EOG AR are of the field 
    % type "'Bad Interval'". The script will find these 'Bad Intervals', 
    % isolate the data, and then remove the values of those segments that 
    % were labelled. In the IC AR, segments that were removed are labeled 
    % by Markers in the field Description. These can vary, but the most
    % common one is 'Bad Amplitude'. EOG removed segments do not seem to
    % have these descriptions, so the script will gather the removed
    % channels in a different variable.
 
    % First, the script gathers the marker types and the marker
    % descriptions.
    segtype = {data.Markers.Type};
    segdes = {data.Markers.Description};
    segchannel = {data.Markers.ChannelNumber};
    
    % Now we prepare variabeles in which we will later write down 
    % codes for what segments and channels will be removed.
    segmenttype = zeros(size(segtype,2),1);
    segmentdescription = zeros(size(segdes,2),1);

    % For EOG AR, the script goes over the segment types and whenever there 
    % is a 'Bad Interval', it will note down 99 in the segmenttype variabele. 
    % If there is no 'Bad Interval' it notes down a 0. 
    % For IC AR, the script notes a 99 if the description is longer than 5 
    % characters - this is most likely a marker from the artifact rejection 
    % as the non-AR markers are either empty or a 'Sxxx' markers. A 0 is 
    % when it is shorter (empty or S marker).
    for marker = 1:size(segtype,2)
        if (strcmp(segtype(marker),'Bad Interval')) && (segchannel{marker} == 0)
           segmenttype(marker) = 99;
        else
            segmenttype(marker) = 0;
        end
        if cellfun('length',segdes(marker))<5
            segmentdescription(marker) = 0;
        else
            segmentdescription(marker) = 99;
        end
    end
    
    % Reshape variabele segmenttype to go back to the structures of
    % segments in the original data structure.
    badintervals = reshape(segmenttype,numseg,size(data.Markers,2));
    badchannels = reshape(segmentdescription,numseg,size(data.Markers,2));
    
    % The data from the structure is isolated in a separate variabele
    % because I could not find a way to integrate it in the structure. 
    dataperchannel = struct2cell(data);
    % Only the first 64 rows are kept because these are the 64 scalp electrodes.
    dataperchannel = dataperchannel(1:64);

    % The script goes over the data per channel and replaces all values with 
    % NaN if there was a 99 noted down in the variabele bad intervals.
    for elec = 1:64
        for seg = 1:numseg
            % EOG artifact rejection
            if any(badintervals(seg),1)
                dataperchannel{elec}(seg,:)=NaN;
            end
            % IC artifact rejection
            for samplepoint=1:size(badchannels,2)
               if (badchannels(seg,samplepoint) == 99)
                  dataperchannel{data.Markers(seg,samplepoint).ChannelNumber}(seg,:)=NaN;
               end
            end
        end
    end

    
    % REMOVE BASELINE
    % Removes the baseline (first 50 datapoints).
    for x = 1:64
        dataperchannel{x}(:,1:50)=[];
    end

    
    % AVERAGE WITHIN SEGMENTS OVER TIME-WINDOWS
    % The script goes over the data per channel. The sampling rate is 500Hz. 
    % If you check data.t, the first 50 samples are the baseline. These 
    % should not be averaged into the segment. After baseline removal the
    % segments are averaged.
    
    % Isolates the data into new variables for the three time-windows
    dataperchannel_100_200=dataperchannel;
    dataperchannel_200_390=dataperchannel;
    dataperchannel_500_900=dataperchannel;
    
    for x = 1:64
        dataperchannel_100_200{x}=dataperchannel_100_200{x}(:,51:101);
        dataperchannel_200_390{x}=dataperchannel_200_390{x}(:,101:196);
        dataperchannel_500_900{x}=dataperchannel_500_900{x}(:,251:451);
    end
    
    % Average the data over segments.
    for x = 1:64
        dataperchannel_100_200{x} = nanmean(dataperchannel_100_200{x},2);
        dataperchannel_200_390{x} = nanmean(dataperchannel_200_390{x},2);
        dataperchannel_500_900{x} = nanmean(dataperchannel_500_900{x},2);
    end
    
    

    
    
    % AVERAGE ACROSS THE CHANNELS FOR THE 9 BRAIN REGIONS
    % Isolates the 64 scalp channels
    channels = {data.Channels(1:64).Name}';

    % Isolates the data of channels and puts it in their respective
    % variables that are related to the brain regions.
    for channel_index = 1:64
        for group_id = 1:region6elec
            if Lant(group_id) == channels(channel_index)
               dataperchan_100_200_lant(:,group_id) = dataperchannel_100_200{channel_index};
               dataperchan_200_390_lant(:,group_id) = dataperchannel_200_390{channel_index};
               dataperchan_500_900_lant(:,group_id) = dataperchannel_500_900{channel_index};
            elseif Lcent(group_id) == channels(channel_index)
                dataperchan_100_200_lcent(:,group_id) = dataperchannel_100_200{channel_index};
                dataperchan_200_390_lcent(:,group_id) = dataperchannel_200_390{channel_index};
                dataperchan_500_900_lcent(:,group_id) = dataperchannel_500_900{channel_index};
            elseif Lpost(group_id) == channels(channel_index)
                dataperchan_100_200_lpost(:,group_id) = dataperchannel_100_200{channel_index};
                dataperchan_200_390_lpost(:,group_id) = dataperchannel_200_390{channel_index};
                dataperchan_500_900_lpost(:,group_id) = dataperchannel_500_900{channel_index};
            elseif Rant(group_id) == channels(channel_index)
                dataperchan_100_200_rant(:,group_id) = dataperchannel_100_200{channel_index};
                dataperchan_200_390_rant(:,group_id) = dataperchannel_200_390{channel_index};
                dataperchan_500_900_rant(:,group_id) = dataperchannel_500_900{channel_index};
            elseif Rcent(group_id) == channels(channel_index)
                dataperchan_100_200_rcent(:,group_id) = dataperchannel_100_200{channel_index};
                dataperchan_200_390_rcent(:,group_id) = dataperchannel_200_390{channel_index};
                dataperchan_500_900_rcent(:,group_id) = dataperchannel_500_900{channel_index};
            elseif Rpost(group_id) == channels(channel_index)
                dataperchan_100_200_rpost(:,group_id) = dataperchannel_100_200{channel_index};
                dataperchan_200_390_rpost(:,group_id) = dataperchannel_200_390{channel_index};
                dataperchan_500_900_rpost(:,group_id) = dataperchannel_500_900{channel_index};
            end         
        end
        for group_id = 1:region3elec
            if Cant(group_id) == channels(channel_index)
               dataperchan_100_200_cant(:,group_id) = dataperchannel_100_200{channel_index}; 
               dataperchan_200_390_cant(:,group_id) = dataperchannel_200_390{channel_index}; 
               dataperchan_500_900_cant(:,group_id) = dataperchannel_500_900{channel_index}; 
            elseif Ccent(group_id) == channels(channel_index)
               dataperchan_100_200_ccent(:,group_id) = dataperchannel_100_200{channel_index};
               dataperchan_200_390_ccent(:,group_id) = dataperchannel_200_390{channel_index};
               dataperchan_500_900_ccent(:,group_id) = dataperchannel_500_900{channel_index};
            elseif Cpost(group_id) == channels(channel_index)
                dataperchan_100_200_cpost(:,group_id) = dataperchannel_100_200{channel_index};
                dataperchan_200_390_cpost(:,group_id) = dataperchannel_200_390{channel_index};
                dataperchan_500_900_cpost(:,group_id) = dataperchannel_500_900{channel_index};
            end
        end
    end

    
    % Save segmented data in the 9 brain regions, but not NaN channel data.
    for seg = 1:numseg
        for chan = 1:region6elec
           segdata_100_200_lant(seg,:)=nanmean(dataperchan_100_200_lant(seg,:));
           segdata_200_390_lant(seg,:)=nanmean(dataperchan_200_390_lant(seg,:));
           segdata_500_900_lant(seg,:)=nanmean(dataperchan_500_900_lant(seg,:));
           segdata_100_200_lcent(seg,:)=nanmean(dataperchan_100_200_lcent(seg,:));
           segdata_200_390_lcent(seg,:)=nanmean(dataperchan_200_390_lcent(seg,:));
           segdata_500_900_lcent(seg,:)=nanmean(dataperchan_500_900_lcent(seg,:));
           segdata_100_200_lpost(seg,:)=nanmean(dataperchan_100_200_lpost(seg,:));
           segdata_200_390_lpost(seg,:)=nanmean(dataperchan_200_390_lpost(seg,:));
           segdata_500_900_lpost(seg,:)=nanmean(dataperchan_500_900_lpost(seg,:));
           segdata_100_200_rant(seg,:)=nanmean(dataperchan_100_200_rant(seg,:));
           segdata_200_390_rant(seg,:)=nanmean(dataperchan_200_390_rant(seg,:));
           segdata_500_900_rant(seg,:)=nanmean(dataperchan_500_900_rant(seg,:));
           segdata_100_200_rcent(seg,:)=nanmean(dataperchan_100_200_rcent(seg,:));
           segdata_200_390_rcent(seg,:)=nanmean(dataperchan_200_390_rcent(seg,:));
           segdata_500_900_rcent(seg,:)=nanmean(dataperchan_500_900_rcent(seg,:));
           segdata_100_200_rpost(seg,:)=nanmean(dataperchan_100_200_rpost(seg,:));
           segdata_200_390_rpost(seg,:)=nanmean(dataperchan_200_390_rpost(seg,:));
           segdata_500_900_rpost(seg,:)=nanmean(dataperchan_500_900_rpost(seg,:));
        end
        for chan = 1:region3elec
           segdata_100_200_cant(seg,:)=nanmean(dataperchan_100_200_cant(seg,:));
           segdata_200_390_cant(seg,:)=nanmean(dataperchan_200_390_cant(seg,:));
           segdata_500_900_cant(seg,:)=nanmean(dataperchan_500_900_cant(seg,:));
           segdata_100_200_ccent(seg,:)=nanmean(dataperchan_100_200_ccent(seg,:));
           segdata_200_390_ccent(seg,:)=nanmean(dataperchan_200_390_ccent(seg,:));
           segdata_500_900_ccent(seg,:)=nanmean(dataperchan_500_900_ccent(seg,:));
           segdata_100_200_cpost(seg,:)=nanmean(dataperchan_100_200_cpost(seg,:));
           segdata_200_390_cpost(seg,:)=nanmean(dataperchan_200_390_cpost(seg,:));
           segdata_500_900_cpost(seg,:)=nanmean(dataperchan_500_900_cpost(seg,:));
        end
    end
   
  
    
    % MAKE R-FRIENDLY FORMAT
    % Save data in R-friendly format
    Pp(:,1)=repmat(regexp(file.name, pattern, 'tokens'),numseg*brainregions,1);
    ERP_pp_100_200 = num2cell(vertcat(segdata_100_200_lant,segdata_100_200_lcent,segdata_100_200_lpost,segdata_100_200_rant,segdata_100_200_rcent,segdata_100_200_rpost,segdata_100_200_cant,segdata_100_200_ccent,segdata_100_200_cpost));
    ERP_pp_200_390 = num2cell(vertcat(segdata_200_390_lant,segdata_200_390_lcent,segdata_200_390_lpost,segdata_200_390_rant,segdata_200_390_rcent,segdata_200_390_rpost,segdata_200_390_cant,segdata_200_390_ccent,segdata_200_390_cpost));
    ERP_pp_500_900 = num2cell(vertcat(segdata_500_900_lant,segdata_500_900_lcent,segdata_500_900_lpost,segdata_500_900_rant,segdata_500_900_rcent,segdata_500_900_rpost,segdata_500_900_cant,segdata_500_900_ccent,segdata_500_900_cpost));
    Pp_ERP_100_200 = horzcat(Pp,ERP_pp_100_200);
    Pp_ERP_200_390 = horzcat(Pp,ERP_pp_200_390);
    Pp_ERP_500_900 = horzcat(Pp,ERP_pp_500_900);
    
    % Add item number to R-friendly format
    % Isolate the markers to check what the condition was.
    cwmarkers = {data.Markers.Description};
    
    % Find out what list the participant received.
    % List 10
    if startsWith(file.name,"ONLY10")
        % Condition A (object accented with context)
        if any(strcmp(cwmarkers, 'S115'))
            % Adds item list to PP_ERP data
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list10{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list10{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list10{1:numseg,1},brainregions,1));
            % Adds accent condition to PP_ERP_list data
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            % Adds context condition to PP_ERP_list_accent data
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        % Condition B (verb accented with context)
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list10{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list10{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list10{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        % Condition C (verb accented with context)
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list10{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list10{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list10{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        % Condition D (object accented with context)
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list10{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list10{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list10{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY11")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list11{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list11{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list11{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list11{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list11{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list11{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list11{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list11{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list11{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list11{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list11{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list11{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY12")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list12{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list12{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list12{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list12{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list12{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list12{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list12{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list12{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list12{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list12{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list12{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list12{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY1")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list1{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list1{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list1{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list1{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list1{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list1{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list1{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list1{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list1{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list1{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list1{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list1{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY2")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list2{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list2{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list2{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list2{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list2{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list2{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list2{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list2{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list2{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list2{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list2{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list2{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY3")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list3{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list3{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list3{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list3{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list3{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list3{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list3{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list3{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list3{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list3{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list3{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list3{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY4")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list4{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list4{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list4{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list4{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list4{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list4{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list4{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list4{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list4{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list4{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list4{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list4{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY5")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list5{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list5{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list5{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list5{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list5{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list5{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list5{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list5{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list5{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list5{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list5{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list5{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY6")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list6{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list6{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list6{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list6{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list6{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list6{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list6{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list6{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list6{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list6{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list6{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list6{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY7")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list7{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list7{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list7{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list7{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list7{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list7{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list7{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list7{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list7{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list7{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list7{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list7{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY8") 
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list8{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list8{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list8{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list8{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list8{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list8{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list8{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list8{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list8{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list8{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list8{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list8{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
        
    elseif startsWith(file.name,"ONLY9")
        if any(strcmp(cwmarkers, 'S115'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list9{1:numseg,1},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list9{1:numseg,1},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list9{1:numseg,1},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S125'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list9{1:numseg,2},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list9{1:numseg,2},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list9{1:numseg,2},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,ones(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,ones(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S135'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list9{1:numseg,3},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list9{1:numseg,3},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list9{1:numseg,3},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("verb",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        elseif any(strcmp(cwmarkers, 'S145'))
            Pp_ERP_item_100_200 = horzcat(Pp_ERP_100_200,repmat(list9{1:numseg,4},brainregions,1));
            Pp_ERP_item_200_390 = horzcat(Pp_ERP_200_390,repmat(list9{1:numseg,4},brainregions,1));
            Pp_ERP_item_500_900 = horzcat(Pp_ERP_500_900,repmat(list9{1:numseg,4},brainregions,1));
            Pp_ERP_item_acc_100_200 = horzcat(Pp_ERP_item_100_200,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_200_390 = horzcat(Pp_ERP_item_200_390,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_500_900 = horzcat(Pp_ERP_item_500_900,repmat("obj",brainregions*numseg,1));
            Pp_ERP_item_acc_con_100_200 = horzcat(Pp_ERP_item_acc_100_200,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_200_390 = horzcat(Pp_ERP_item_acc_200_390,zeros(brainregions*numseg,1));
            Pp_ERP_item_acc_con_500_900 = horzcat(Pp_ERP_item_acc_500_900,zeros(brainregions*numseg,1));
        end
    end
    
    
    
    % ADD CONTEXT, LATERALIZATION, AND ANTERIORITY TO THE FORMAT
    Pp_ERP_item_acc_con_lat_100_200 = horzcat(Pp_ERP_item_acc_con_100_200,repmat(lateralization,numseg,1));
    Pp_ERP_item_acc_con_lat_200_390 = horzcat(Pp_ERP_item_acc_con_200_390,repmat(lateralization,numseg,1));
    Pp_ERP_item_acc_con_lat_500_900 = horzcat(Pp_ERP_item_acc_con_500_900,repmat(lateralization,numseg,1));
    Pp_ERP_item_acc_con_lat_ant_100_200 = horzcat(Pp_ERP_item_acc_con_lat_100_200,repmat(anteriority,3*numseg,1));
    Pp_ERP_item_acc_con_lat_ant_200_390 = horzcat(Pp_ERP_item_acc_con_lat_200_390,repmat(anteriority,3*numseg,1));
    Pp_ERP_item_acc_con_lat_ant_500_900 = horzcat(Pp_ERP_item_acc_con_lat_500_900,repmat(anteriority,3*numseg,1));
    
    
    % ADD GROUP TO FORMAT
    if endsWith(file.name,"7")
        Pp_ERP_item_acc_con_lat_ant_group_100_200 = horzcat(Pp_ERP_item_acc_con_lat_ant_100_200,repmat("NL",brainregions*numseg,1));
        Pp_ERP_item_acc_con_lat_ant_group_200_390 = horzcat(Pp_ERP_item_acc_con_lat_ant_200_390,repmat("NL",brainregions*numseg,1));
        Pp_ERP_item_acc_con_lat_ant_group_500_900 = horzcat(Pp_ERP_item_acc_con_lat_ant_500_900,repmat("NL",brainregions*numseg,1));
    else 
        Pp_ERP_item_acc_con_lat_ant_group_100_200 = horzcat(Pp_ERP_item_acc_con_lat_ant_100_200,repmat("ENG",brainregions*numseg,1));
        Pp_ERP_item_acc_con_lat_ant_group_200_390 = horzcat(Pp_ERP_item_acc_con_lat_ant_200_390,repmat("ENG",brainregions*numseg,1));
        Pp_ERP_item_acc_con_lat_ant_group_500_900 = horzcat(Pp_ERP_item_acc_con_lat_ant_500_900,repmat("ENG",brainregions*numseg,1));
    end
    
    all_erptrialdata_100_200 = vertcat(all_erptrialdata_100_200,Pp_ERP_item_acc_con_lat_ant_group_100_200);
    all_erptrialdata_200_390 = vertcat(all_erptrialdata_200_390,Pp_ERP_item_acc_con_lat_ant_group_200_390);
    all_erptrialdata_500_900 = vertcat(all_erptrialdata_500_900,Pp_ERP_item_acc_con_lat_ant_group_500_900);
end

writematrix(all_erptrialdata_100_200, 'NL_ENG_erptrialsdata_100_200.txt')
writematrix(all_erptrialdata_200_390, 'NL_ENG_erptrialsdata_200_390.txt')
writematrix(all_erptrialdata_500_900, 'NL_ENG_erptrialsdata_500_900.txt')
