ucdavis / erplab

ERPLAB Toolbox is a free, open-source Matlab package for analyzing ERP data. It is tightly integrated with EEGLAB Toolbox, extending EEGLAB’s capabilities to provide robust, industrial-strength tools for ERP processing, visualization, and analysis. A graphical user interface makes it easy for beginners to learn, and Matlab scripting provides enormous power for intermediate and advanced users.
http://erpinfo.org/erplab
262 stars 75 forks source link

bepoch2EL() assigns EEG.EVENTLIST.eventinfo.bepoch values incorrectly when EEG.EVENTLIST.eventinfo.item is misordered #128

Open Bysmuth opened 4 years ago

Bysmuth commented 4 years ago

Description

When pop_epochbin() is called, it sometimes assigns incorrect values to EEG.EVENTLIST.eventinfo.bepoch. Specifically, .bepoch values are sometimes shifted, so that (e.g.) a .bepoch value that should have been assigned to row n is assigned to row n+1. This seems to occur when EEG.EVENTLIST.eventinfo.item is not equal to precisely 1:n, where n = size(EEG.EVENTLIST.eventinfo,2).

I tracked this behavior to bepoch2EL lines 112-133, which use EEG.epoch.eventitem values as row indexes in EEG.EVENTLIST.eventinfo to assign values of EEG.EVENTLIST.eventinfo.bepoch. That works when EEG.EVENTLIST.eventinfo.item values are equal to row numbers, but leads to misalignment otherwise.

I’m not sure what this actually affects (it doesn’t seem to matter for pop_averager() at least, which is reassuring!), but it did throw off some custom functions that relied on EEG.EVENTLIST.eventinfo.bepoch.


Steps to Reproduce

Run the following two lines of code, which start .item values at 2, then call pop_epochbin():

item_nums_shifted = num2cell(2:(1+size(EEG.EVENTLIST.eventinfo,2)));
[EEG.EVENTLIST.eventinfo.item] = item_nums_shifted{:};


Expected behavior:

I expect that EEG.EVENTLIST.eventinfo.bepoch values will align with critical events (those that have .binlabel values ~= '""' and .bini values ~= -1).


Actual behavior:

Given the code above, .bepoch values will match critical events in the immediately preceding row of EEG.EVENTLIST.eventinfo. More generally, EEG.EVENTLIST.eventinfo(n).bepoch will match row # find([EEG.EVENTLIST.eventinfo.item] == n) .


Versions

OS version OS X 10.13.6
Matlab version 2018b
EEGLAB version 2019.1
ERPLAB version 7.0