[FieldTrip] convert fieldtrip components to eeglab for IClabel

Arnaud Delorme arnodelorme at gmail.com
Fri Mar 11 21:35:46 CET 2022


One solution below. Maybe not the most elegant. I assume you want to use ft_preprocessing to preprocess your data (otherwise you can just import the file in EEGLAB directly and convert it to Fieldtrip at the end).
Pull the changes on EEGLAB git (or update the pop_fileio EEGLAB function called by fieldtrip2eeglab, as I have changed it so it would be able to convert Fieldtrip ft_raw_data structures to EEGLAB datasets https://github.com/sccn/eeglab/blob/develop/functions/popfunc/pop_fileio.m)

The bottom section for conversion back to fieldtrip is a hack accessing Fieldtrip private folder. 
You can also use the function eeglab2fieldtrip (tailored to DIPFIT - dipole localization).

Arno

% preprocess file in Fieldtrip
cfg = [];
cfg.datafile = '~/data/matlab/eeglab/sample_data/eeglab_data.set';
cfg.headerfile = '~/data/matlab/eeglab/sample_data/eeglab_data.set';
my_ft_data = ft_preprocessing(cfg);

% Run ICA and IC label in EEGLAB
EEG = fieldtrip2eeglab(my_ft_data, my_ft_data.trial);
EEG = eeg_checkset(EEG);
EEG = pop_runica(EEG, 'icatype', 'runica');
EEG = pop_icflag(EEG, [0 0;0 0; 0.001 1; 0 0; 0 0; 0 0; 0 0]); % see function help message
rejected_comps = find(EEG.reject.gcompreject > 0);
EEG = pop_subcomp(EEG, rejected_comps);
EEG = eeg_checkset(EEG);

% convert back to Fieldtrip
curPath = pwd;
p = fileparts(which('ft_read_header'));
cd(fullfile(p, 'private'));
hdr = read_eeglabheader( EEG );
data = read_eeglabdata( EEG, 'header', hdr );
event = read_eeglabevent( EEG, 'header', hdr );
cd(curPath);





More information about the fieldtrip mailing list