@@ -343,6 +343,10 @@ See [General Post-Happe Steps](#generalPost) for examples of the MATLAB code and
343343 - The c/x indicator will be appended to the front of the existing event tag (e.g., `Go++` will become `cGo++`)
344344 - Export an updated version of the .mff file with accuracy information to the specified location ("pathSub")
345345
346+ **NOTE: When exporting EEG data from MATLAB, it is absolutely necessary for the data to be organized in order of event latency.**
347+ **If the rows are out of order, latency errors may be introduced.**
348+ - Correct row order can be achieved in `.mff` filetypes by sorting according to either the `latency` column or the `urevent` column (as shown below)
349+
346350 ```
347351 for row = 1:height(mergePaths)
348352 % Specify paths
@@ -417,10 +421,17 @@ See [General Post-Happe Steps](#generalPost) for examples of the MATLAB code and
417421 % Replace codes where new code is needed
418422 EEGnew.code(~strcmp(EEGnew.newCode, '')) = EEGnew.newCode(~strcmp(EEGnew.newCode, ''))
419423 EEGnew.type(~strcmp(EEGnew.newCode, '')) = EEGnew.newCode(~strcmp(EEGnew.newCode, ''))
420- EEGnew = table2struct(EEGnew(:, 1:28))
421424
422- % Replace event table in original struct
425+ % Arrange table in order of event (CRUCIAL for correct export)
426+ EEGnew = sortrows(EEGnew, 'urevent')
427+
428+ % Convert table back to struct and restore original dimensions
429+ EEGnew = table2struct(EEGnew(:, 1:29))
430+ EEGnew = reshape(EEGnew, [1, height(EEGnew)])
431+
432+ % Replace event table(s) in original struct
423433 EEGraw.event = EEGnew
434+ EEGraw.urevent = table2struct(struct2table(EEGnew(:, 1:28)))
424435
425436 % Export updated file
426437 pop_mffexport(EEGraw, char(subFolder))
0 commit comments