0

I got a batch of processed datasets in eeglab. I want to export all of them into txt in a batch, however, it seems like must be done file by file.

I am new to eeglab and matlab. Could someone please help me with this?

Yuan Yue
  • 1
  • 1
  • I don't think EEGLAB can do this from the GUI, but you should direct that question to the eeglab mailing list: https://eeglab.org/others/EEGLAB_mailing_lists.html. You can do this pretty easily using matlab code. I will post an answer showing how to do this. – dmedine Mar 03 '22 at 03:38

1 Answers1

0

This code was tested by being run in my directory with EEGLAB in it. In my case there are 2 data sets with associated .fdt files in that directory as well. If your .set files are in a different directory from EEGLAB, you will have to change the code to find them there. The script must be in the EEGLAB directory, or else the EEGLAB source must be in your PATH, but I think that putting EEGLAB's code in your PATH is not a recommended setup.

I use regular expression (regexp) to find which files are .set files and to build the output filenames. If you are not familiar with regular expressions, just do a websearch.

% read all the files in the directory
files = dir();

% parse directory contents for .set files
sets = {};
idx = 1;
for n=1:length(files)
    if(regexp(files(n).name,'.set'))
        sets{idx} = files(n).name;
        idx = idx+1;
    end
end

% load the data sets and write the data to appropriate filename
for n=1:length(sets)
   % change the argument after filepath to the path your EEGLAB
   % instalation is in
   % note the double '\' directory delimiter is for Windows
   EEG = pop_loadset('filename', sets{n},'filepath','C:\\Users\\david.medine\\matlab\\toolboxes\\eeglab2019_0\\');
   EEG = eeg_checkset( EEG ); 
   outputfilename = sprintf('%stxt', sets{n}(1:regexp(sets{n}, '.set')))
   writematrix(EEG.data, outputfilename);
end

By the way, I knew what functions to call from EEGLAB to load the .set files by checking >> EEG.history. That will show all the Matlab code that went on behind the GUI scenes in your EEGLAB session.

EEGLAB stores the data in vectorized orientation. If you want multiplexed simply transpose the matrix:

writematrix(EEG.data', outputfilename);
dmedine
  • 1,430
  • 8
  • 25
  • Thanks a lot for you timely help first! The datasets I got are not arrays. Initially, they were in edf format, after using eeglab to do preprocessing, they were resaved into .set format. So I will need to export all the .set files into .txt . Could you please help with this using the Matlab code? – Yuan Yue Mar 03 '22 at 04:37
  • I will adjust the answer. – dmedine Mar 03 '22 at 05:09
  • Thanks for updating! Still one error pop up states "Error using ==> load Unable to read MAT-file C:\sub1 Prmtrs.mat: not a binary MAT-file. Try LOAD -ASCII to read as text". Do you have an idea about how to deal with this? Thanks – Yuan Yue Mar 03 '22 at 21:41
  • This is not the right forum for debugging an EEGLAB session. Please consult the EEGLAB mailing list or forum and provide them with the precise details that cause this error. – dmedine Mar 03 '22 at 23:23