[Eeglablist] script for importing .mat files

Tarik S Bel-Bahar tarikbelbahar at gmail.com
Fri Jan 2 09:55:47 PST 2015

Greetings Muhammad, This should get easy to do once you have the hang of it
Here are some notes below that you might find useful. Best wishes for your
new year!

1. If you haven't had a chance to, try looking through the tutorial wiki on
EEGLAB scripting, as well as related slides and talks from the EEGLAB
schools. There should be some good ideas to help you there. Further, there
is some basic matlab familiarity that is required to do scripting in
eeglab. For example, see the "relevant Reading and Materials" section of a
recent EEGLAB Summer School: http://sccn.ucsd.edu/wiki/EEGLAB_2014_Rio

2. For doing what you need to 80 files, you could consider the eeglab BATCH
plugin from Desjardins.

3. For looping through files, you basically need to setup a list of all the
files names, and then create a loop that, for each file, opens it with the
correct commands and settings, does what ever steps and saves you want -
again using the correct commands and settings, and then restarts the loop
to start working on the next file. The loop should begin with an import of
the file, and then should end with a save of the file (with any changes to
the filename that you need, etc…].
so for example things would look like this, generally [this is a very
simple example of course!]

for MuhammadLoop = 1: (length(MuhammadFileNames))
theCurrentFile = MuhammadFileNames(MuhammadLoop)
…import and do stuff here to theCurrentFile
…save theCurrentFile's new version
…clear all EEG datasets

4. If you can do a step through the GUI, then most or all of the
information you need to run that step as a script can be gotten through
eegh (eeglab history). Closely review and imitate the information you get
from there. In most cases, try to repeat exactly what the eeglab history
says, rather than skipping any steps (until you know which ones you can
skip :) For basic users, usually all the information needed is in eegh.

5. I would generally recommend first getting your files all in eeglab
format, and then doing whatever series of steps you want on them. So have
an "import" loop, and then a "processing" loop. I would also recommend
steps in your loop where you change the string of the file name, and edit
the set information as necessary.

6. You do need a little familiarity with matlab. For example, as might
guess, you will have to, for each file loop in your script, have a variable
name that is "theCurrentFile". If you need to, for any basic matlab
functions or questions, such as to get a file directory, please also try
searching for your topic and "Matlab". e.g., Search on google: "get
directory of files names matlab"

On Thu, Jan 1, 2015 at 11:11 PM, Muhammad Adeel Parvaz <mparvaz at gmail.com>

> Hi,
> I am new to EEGLAB. I have an EEG data (.mat) that I can successfully
> import it in EEGLAB, use the last channel (#65) to load events and then
> save the data as a .set and .fdt pair. However, I have about 80 of these
> files and I would like to repeat these 3 processes to each of these files.
> I looked into doing it through GUI on the first file and then using the
> dataset history to get the commands for each step and applying to other
> files, but I am not quite sure how to do that.
> By the way, I can manually import a bunch of files and then run the
> history commands to automatically perform the other two steps. So, the
> automatic import seems to be the limiting factor. I would ideally like the
> script to run through the directory and perform these steps on each file.
> My command history for one dataset looks like this:
> pop_read_gtec(ALLEEG) % importing function supplied by the vendor
> EEG = eeg_checkset( EEG );
> EEG = pop_chanevent(EEG, 65,'edge','leading','edgelen',0);
> EEG = eeg_checkset( EEG );
> EEG = pop_saveset( EEG,
> 'filename','S001_Oddball.set','filepath','C:\\Users\\Documents\\MATLABfiles\\EEG_Data\\Test\\');
> EEG = eeg_checkset( EEG );
> Any and every help would be much appreciated.
> Thanks and a happy new year!
> -Muhammad
> _______________________________________________
> Eeglablist page: http://sccn.ucsd.edu/eeglab/eeglabmail.html
> To unsubscribe, send an empty email to
> eeglablist-unsubscribe at sccn.ucsd.edu
> For digest mode, send an email with the subject "set digest mime" to
> eeglablist-request at sccn.ucsd.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20150102/649903ce/attachment.html>

More information about the eeglablist mailing list