Skip to content

Commit

Permalink
fixed copying of badtrials and events in case of a mismatch in trialn…
Browse files Browse the repository at this point in the history
…umbers.
  • Loading branch information
Mats van Es authored and Mats van Es committed Aug 24, 2020
1 parent 098766a commit 3e77a46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions oat/oat_run_first_level_epoched.m
Expand Up @@ -642,6 +642,7 @@
Sc.frequencies = first_level_results.frequencies(f);
Sc.remove_montages=0;
Sc.cond_list = D.conditions(triallist);
Sc.events = D.events(triallist);
D_tf = osl_change_spm_eeg_data( Sc );

% add back in Class channel:
Expand Down
8 changes: 6 additions & 2 deletions osl_change_spm_eeg_data.m
Expand Up @@ -111,14 +111,18 @@

% copy badtrials
badtrials=D.badtrials;
if ~isempty(badtrials)
if ~isempty(badtrials) && Sc.D.ntrials==D2.ntrials
tmp_bad = zeros(D.ntrials,1);
tmp_bad(badtrials) = 1;
D2 = D2.badtrials(1:length(tmp_bad),tmp_bad);
end

% copy events
ev = D.events;
if isfield(Sc, 'events') % required when number of trials in D and D2 is not equal
ev = Sc.events;
else
ev = D.events;
end
D2 = D2.events(1:D2.ntrials,ev);

end
Expand Down

0 comments on commit 3e77a46

Please sign in to comment.