Station 9 · Lesson 1

eegh & the command history

Core10 minBefore this lesson: Extracting epochsPrint the card
Starts from: eeglab_data.set (D1) · Nothing yet: the data as downloaded.Download the data (opens in a new tab)
Script to reach this state
MATLAB
% Start a fresh EEGLAB session so the history begins empty
clear
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;

The idea in brief

Every click in the EEGLAB window runs a line of MATLAB behind the scenes. EEGLAB keeps these lines, in order, in the command historyThe list of commands the GUI has run, shown by the eegh command., and the eegh command shows them to you.

Before and after

The Filter the data -- pop_eegfiltnew() window with 0.1 in Lower edge of the frequency pass band (Hz) and Plot frequency response checked.
EEGLAB 2026.1Screenshot of the EEGLAB interface (SCCN)
What does this show?

After you click Ok in this window, type eegh in the command window. The matching line is:

MATLAB
EEG = pop_eegfiltnew(EEG, 'locutoff',0.1,'plotfreqz',1);

Each field you filled in the window is in the line: 'locutoff',0.1 is the lower edge, and 'plotfreqz',1 is the ticked Plot frequency response box.

Your next questions, each answered in its own section:

Why do I need this step?

The reasons in detail, and the terms you need

This history is your first scriptA MATLAB file of commands that runs processing steps in order., and you did not type a single character of it. Save it to a file, and you can repeat the same analysis in one click, or apply it to another participantThe person whose data were recorded in the study..

The history is also an exact record of what you did. A month from now you will not remember which filterA tool that weakens some frequencies in a signal and keeps others. edge you chose. The history will.

How do I do it in EEGLAB?

11 steps in the menus

Start a fresh session as in “Starting point”: clear, then eeglab. Running eeglab starts a new, empty history, so it does not mix with commands from an earlier session.

First: run a few steps from the GUIThe windows and menus used with the mouse instead of typed commands.

  1. Open File then Load existing dataset and choose eeglab_data.set from the sample_data folder inside the EEGLAB folder.
  2. Open Tools then Filter the data then Basic FIR filter (new, default). Type 0.1 in Lower edge of the frequency pass band (Hz) and press Ok. Close the filter response window and name the datasetOne EEG data file loaded in EEGLAB together with its information. D1 hp0.1.
  3. Open the same menuA list of commands that opens from its name at the top of the window. again to remove 60 Hz line noiseInterference from the mains supply at 60 Hz in Saudi Arabia or 50 Hz elsewhere.. Type 58 in Lower edge of the frequency pass band (Hz) and 62 in Higher edge of the frequency pass band (Hz), and check Notch filter the data instead of pass band. Press Ok and name the dataset D1 hp0.1 notch60.
  4. Open Plot then Channel data (scroll), then close the window.

Second: show the history

  1. In the MATLAB command window, type eegh and press Enter. EEGLAB prints every command of the session, oldest first. It will look like this (your path will differ):
MATLAB
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;
EEG = pop_loadset('filename','eeglab_data.set','filepath','C:\eeglab2026.1\sample_data\');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
EEG = pop_eegfiltnew(EEG, 'locutoff',0.1,'plotfreqz',1);
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 1,'setname','D1 hp0.1','gui','off');
EEG = pop_eegfiltnew(EEG, 'locutoff',58,'hicutoff',62,'revfilt',1,'plotfreqz',1);
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'setname','D1 hp0.1 notch60','gui','off');
pop_eegplot( EEG, 1, 1, 1);
  1. Match each line to its step. Notice that the Notch filter the data instead of pass band checkbox became 'revfilt',1, and Plot frequency response became 'plotfreqz',1. This is how you learn the script name of each option from the GUI itself.

Third: save the history to a file

  1. Open File then History scripts then Save session history script. The suggested name is eeglabhist.m. Change it to my_first_history.m and save it in your working folder.
  2. Type EEG.history in the command window. This is the dataset history: the commands for the current dataset only, without the dataset management commands. It starts with lines you did not write, with paths like /Users/arno/...: this is the file’s history on the computers of the people who made it, because the history is saved inside the .set file and travels with it. Then comes a line that records the EEGLAB version, then the two filter lines, and at the end a pop_eegplot line, because you opened the scroll window from the menu.
  3. To save it to a file, open File then History scripts then Save dataset history script.

Fourth: run the history

  1. Close EEGLAB, then type clear and close all.
  2. Open my_first_history.m in the MATLAB editor and press Run. All the steps repeat on their own, and the scroll window opens at the end. You can also run it from File then History scripts then Run script.
Session history or dataset history?

The session history (eegh) keeps everything you did in the session, for all datasets, and it is lost when you run eeglab again if you did not save it. The dataset history (EEG.history) keeps what changed this dataset only, and it is saved inside the .set file, so you will still find it a year later when you open the file.

How do I write it as code?

The same steps in 15 lines of MATLAB

The history script works as is, but it is written for the machine, not for you. Clean it before you rely on it. Here is the same history after cleaning:

MATLAB
% Rebuilt from the EEGLAB session history (eegh)
eeglab nogui
eeglabRoot = fileparts(which('eeglab'));

% Load the sample dataset (portable path, works on any computer)
EEG = pop_loadset('filename', 'eeglab_data.set', 'filepath', fullfile(eeglabRoot, 'sample_data'));

% High-pass: passband edge at 0.1 Hz
[EEG, com] = pop_eegfiltnew(EEG, 'locutoff', 0.1);
EEG = eeg_hist(EEG, com);

% Line noise: notch between 58 and 62 Hz
[EEG, com] = pop_eegfiltnew(EEG, 'locutoff', 58, 'hicutoff', 62, 'revfilt', 1);
EEG = eeg_hist(EEG, com);
EEG.setname = 'D1 hp0.1 notch60';
EEG = eeg_checkset(EEG);

% Save the dataset history to a file, for your records
pop_saveh(EEG.history, 'D1_hp0.1_notch60_history.m', pwd);

What changed from the raw history:

  • The fixed path became fullfile(eeglabRoot, 'sample_data'), so the script works on any computer.
  • 'plotfreqz',1 was removed, so no step stops at a plot window.
  • The eeg_store and pop_newset lines were removed, because they manage datasets in the GUI. The script works on a single EEG variable, and the name goes in EEG.setname.
  • eeglab nogui replaces eeglab, so EEGLAB loads its functions without opening the main window.
  • Comments were added, because a line of code says what it does, and a comment says why.
  • [EEG, com] and eeg_hist were added. pop_ functions return their command line as the second output com, and eeg_hist adds it to EEG.history. Without them the dataset history stays empty of the script’s steps, because EEGLAB writes the history automatically only for commands run from the menus.
pop_saveh from a script

pop_saveh does the same as the Save dataset history script menu item. To save the session history from a script, type pop_saveh(ALLCOM, 'session_history.m', pwd).

Which value should I choose?

Suitable values for your analysis goal
You want toUseWhy
Repeat everything you did today, across all datasetsSession history: eegh or Save session history scriptIt includes the load, save and dataset management commands, so it replays the whole session.
Know how a specific .set file was madeDataset history: EEG.historyIt is saved inside the file itself, so it stays with the data (official EEGLAB tutorial, section EEGLAB dataset history).
Build a script for other participantsThe dataset history, cleanedIt is shorter and has no GUI commands, so it moves easily into a loop over participants (the batch processingRunning the same script automatically on many participants' files. lesson).

How do I check it worked?

3 quick checks
  1. The script runs on its own. Run the clean script in a fresh session. It should finish without any error and without asking you to click anything.
  2. Same processing. After it runs, type EEG.history. You should see the two filter lines with the same numbers you chose in the GUI: 0.1, then 58 and 62 with 'revfilt',1.
  3. The history file exists. In your working folder you should find D1_hp0.1_notch60_history.m. Open it, and you will find the same two filter lines.

What mistakes do people make?

4 mistakes and how to avoid them
  • Running eeglab again before saving the session history. eeglab starts an empty history. Save the history first, or rely on the EEG.history saved with the dataset.
  • Sharing a script with a fixed path. A line like 'filepath','C:\Users\...' will not work on your colleague’s computer. Replace it with fullfile as in the script above.
  • Expecting steps run outside the menus to be recorded. EEGLAB writes the history for commands run from the menus only. What you type yourself in the command window does not appear in eegh, and running pop_eegfiltnew from a script does not change EEG.history. If you want the saved file to carry its history, add EEG = eeg_hist(EEG, com); after each step, as in the script above.
  • Running the dataset history as is. It starts with old lines from the file’s creator, with paths from their computer, so it stops at the first line. Copy only the processing lines from it, and start your script with a load command that uses a path from your own computer.

Where can I read more?

2 sources, official docs first

Written for EEGLAB 2026.1 · 2026-10-28

Need help?

Ask, share feedback, or report an error