Skip to main content
Social Sci LibreTexts

11.7: Exercise- EEG.history and eegh

  • Page ID
    137733
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    EEGLAB has a super convenient history feature, which we shamelessly copied when we created ERPLAB. Whenever you run a routine from the EEGLAB GUI, the equivalent command text is saved in the history. The history field of the EEG variable (i.e., EEG.history) stores the history of the routines that were applied to that specific dataset, and you can see this history by simply typing EEG.history on the command line. You can also get a history of everything that was done since the last time you launched EEGLAB (which might include routines applied to many different datasets) by typing eegh on the command line.

    Go to the Datasets menu and select the first dataset (which should be named My First Custom Dataset). The first dataset should now be stored in the EEG variable, and if you type EEG.history you should see the history of the routines that were applied to this dataset:

    EEG = pop_loadset('filename','1_N170.set','filepath','/Users/luck/Dropbox/Research/Manuscripts/ERP_Analysis_Book/Ch_10_Scripting/Exercises/');

    EEG = eeg_checkset( EEG );

    EEG = eeg_checkset( EEG );

    The first line is the command you used to load the dataset from a file. This is followed by two eeg_checkset commands. This command just verifies that everything is okay in the dataset. It was run once when you first loaded the dataset, and then it was run again when you switched from the second dataset back to the first dataset. Notice that the Matlab command that you used to change the name of the dataset isn’t in the history. Only EEGLAB GUI operations are automatically saved in the history.

    I want to pause for a minute and encourage you to appreciate what just happened. You used your mouse to load the dataset using the EEGLAB GUI, which should have been simple and natural now that you’ve spent a lot of time using EEGLAB. And then the history allowed you to see the actual Matlab command that was used to load the dataset. This is the same command you’ll use to load datasets when you start writing scripts. So, you don’t need to read some opaque documentation to figure out what command to use and how to use it. You just need to run the routine from the GUI and look at the history.

    This makes scripting so much easier! And it’s not just for beginners: when I created the scripts for each chapter of this book, I first ran the routines from the GUI so that I could get the history, which I then copied into the scripts that I was writing. I’m not sure which of the original EEGLAB developers came up with this scheme, but it’s brilliant!

    Now that I’ve gushed about how great this is, I want to note a small complication. If you look closely at the pop_loadset command that was used to load the dataset, you’ll see that it specifies the filename ('filename', '1_N170.set') and the location of the file on your hard drive (the path to the file, listed in the string following 'filepath'). However, the path that you can see on your computer is not the same as the path shown above, which shows the path on my computer ('/Users/luck/Dropbox/Research/Manuscripts/ERP_Analysis_Book/Ch_10_Scripting/Exercises/').

    Keep in mind that the paths you’ll see in this book won’t be the same as the paths you’ll see on your computer. And paths can be confusing even when you’re not using this book. One of the most common problems people have when learning to write scripts is getting the paths wrong. I often get them wrong myself. Later, I’ll show you some strategies for reducing the likelihood of having path problems.

    Now select the second dataset in the Datasets menu, and type EEG.history to see the history for that dataset:

    EEG = pop_loadset('filename','1_N170.set','filepath','/Users/luck/Dropbox/Research/Manuscripts/ERP_Analysis_Book/Ch_10_Scripting/Exercises/');

    EEG = eeg_checkset( EEG );

    EEG  = pop_basicfilter( EEG,  1:33 , 'Boundary', 'boundary', 'Cutoff', [ 0.1 30], 'Design', 'butter', 'Filter', 'bandpass', 'Order',  2, 'RemoveDC', 'on' ); % GUI: 10-Jun-2021 09:49:46

    EEG.setname='1_N170_filt';

    EEG = eeg_checkset( EEG );

    EEG = eeg_checkset( EEG );

    You’ll see that the first couple lines are the same as the history for the first dataset. That’s because those commands are part of the sequence of operations that was applied to the second dataset. Following those lines, you can see the command for filtering the EEG. When you saved the filtered dataset, that generated an additional command for setting the new setname value.

    Now type eegh to see the history for the current EEGLAB session. It should look something like this:

    [ALLEEG EEG CURRENTSET ALLCOM] = eeglab;

    EEG = pop_loadset('filename','1_N170.set','filepath','/Users/luck/Dropbox/Research/Manuscripts/ERP_Analysis_Book/Ch_10_Scripting/Exercises/');

    [ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );

    EEG  = pop_basicfilter( EEG,  1:33 , 'Boundary', 'boundary', 'Cutoff', [ 0.1 30], 'Design', 'butter', 'Filter', 'bandpass', 'Order',  2, 'RemoveDC', 'on' ); % GUI: 10-Jun-2021 10:08:08

    [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 1,'setname','1_N170_filt','gui','off');

    [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'retrieve',1,'study',0);

    [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 1,'retrieve',2,'study',0);

    The first line is the command for launching EEGLAB, which returns the ALLEEG and EEG variables (which are empty initially). It also returns a variable named CURRENTSET, which just indicates which dataset is currently active, and a variable named ALLCOM, which stores the history.

    The second line is the command for loading the first dataset from your hard drive into the EEG variable. This is followed by an eeg_store command that adds it to the ALLEEG variable. It would be possible to replace this with ALLEEG(1) = EEG, but the eeg_store command takes care of a few additional details (like updating the value of CURRENTSET).

    The next line is for the filtering routine, which operates on the EEG variable. This is followed by a pop_newset command that creates an entry for this new dataset in the ALLEEG variable (and sets the setname). We then have two more pop_newset commands that correspond to you setting the first dataset to be active in the Datasets menu and then setting the second dataset to be active in the Datasets menu.

    You now know how to see the Matlab commands for all the routines you know how to run from the EEGLAB GUI. This will make your life much easier in the following exercises, where you’ll start putting together scripts. I like to use eegh when I’m writing scripts that will interact with the EEGLAB GUI, where it’s important to keep track of ALLEEG and CURRENTSET. But I typically use EEG.history for scripts that run independently of the GUI, in which case I typically have only one dataset in memory at a given time and don’t need to worry about ALLEEG.


    This page titled 11.7: Exercise- EEG.history and eegh is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Steven J Luck directly on the LibreTexts platform.