l.53 should be modified to be consistent with line 67 : EEGorig = pop_loadset(fname_orig.name, fname_orig.folder) ;
l.94: the way the autorej column is searched leads to several column indices. It should search with the threshold of automatic rejection, which can be found in EEGorig.history_stepB.rej_high. Accordingly, I suggest to modify l.94 as such: idx_column = contains(T1.Properties.VariableNames,num2str(EEGorig.history_stepB.rej_high));
for participant DVL_038_T10 and DVL_045_T10, discrepancy between number of trials detected for manual rejection and number of trials to mark as automatically rejected in trials_description. For example, for cond DEV2 in DVL_038_T10, only 46 events found for 'idx_before_manual_rej' although it should be 51-> that's why there is an error when trying to update flag variable (number of trials exceed 46)
In this function, several issues: