Station 1 · Lesson 3
The EEG structure
eeglab_data.set (D1) · Nothing yet: the data as downloaded.Download the data (opens in a new tab)Script to reach this state
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
sampleFolder = fullfile(fileparts(which('eeglab')), 'sample_data');
EEG = pop_loadset('filename', 'eeglab_data.set', 'filepath', sampleFolder);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, 0, 'setname', 'Continuous EEG Data', 'gui', 'off');
eeglab redraw;Your browser's back button takes you to the exact place you were, so open anything you like.
The idea in brief
Everything you see in the EEGLAB window is stored in a single MATLAB variable called EEG. This variable is a structA MATLAB variable that groups several named fields together.: a box of fields, each with a name.
The main window shows only a summary. Scripts read from EEG and write to it directly. Once you understand its main fields, you can check any step yourself.
Before and after
Your next questions, each answered in its own section:
Why do I need this step?
The reasons in detail, and the terms you need
You will use the same dot syntax you used with the demo variable in the MATLAB basics lesson: EEG.srate means the srate field inside EEG.
Why do I need this step?
You will use the same dot syntax you used with the demo variable in the MATLAB basics lesson: EEG.srate means the srate field inside EEG.
How do I do it in EEGLAB?
7 steps in the menus
1. Open the fields in the Workspace
- Open the datasetOne EEG data file loaded in EEGLAB together with its information. as in the previous lesson.
- In the MATLAB Workspace panel, double-click
EEG. - The fields of
EEGappear in a table. Double-click any field to open it, such aschanlocsorevent.
2. Read the events from EEGLAB
- Open Edit then Event values.
- A window shows one eventA marker in the recording that flags a moment of interest, such as a stimulus. at a time:
type,positionandlatency. (Theureventfield is not shown in this window.) - Notice that the latency field in this window is titled latency (sec): the window shows the latency in seconds, while
EEG.eventstores it in samples. The first event appears here at about 1.0001 seconds. - Close the window with Cancel so you do not change anything.
3. Read the dataset information
Open Edit then Dataset info. Values such as the dataset name and sampling rateThe number of samples recorded per second on each channel. appear. Close it with Cancel.
How do I do it in EEGLAB?
1. Open the fields in the Workspace
- Open the dataset as in the previous lesson.
- In the MATLAB Workspace panel, double-click
EEG. - The fields of
EEGappear in a table. Double-click any field to open it, such aschanlocsorevent.
2. Read the events from EEGLAB
- Open Edit then Event values.
- A window shows one event at a time:
type,positionandlatency. (Theureventfield is not shown in this window.) - Notice that the latency field in this window is titled latency (sec): the window shows the latency in seconds, while
EEG.eventstores it in samples. The first event appears here at about 1.0001 seconds. - Close the window with Cancel so you do not change anything.
3. Read the dataset information
Open Edit then Dataset info. Values such as the dataset name and sampling rate appear. Close it with Cancel.
How do I write it as code?
The same steps in 18 lines of MATLAB
Type these lines in the Command Window, one at a time, and compare the output with the comment:
% Basic information
EEG.setname % 'Continuous EEG Data'
EEG.nbchan % 32 channels
EEG.srate % 128 samples per second
EEG.pnts % 30504 samples per channel
(EEG.pnts - 1) / EEG.srate % 238.3047 seconds (same as EEG.xmax)
% The signal: channels x samples
size(EEG.data) % 32 30504
class(EEG.data) % 'single'
EEG.data(1, 1:5) % first 5 samples of channel 1 (microvolts)
% Channel names
{EEG.chanlocs(1:3).labels} % 'FPz' 'EOG1' 'F3'
% First event: type and latency
EEG.event(1).type % 'square'
EEG.event(1).latency % 129.0087 (in samples)
(EEG.event(1).latency - 1) / EEG.srate % 1.0001 (in seconds)
% Empty until ICA is computed
isempty(EEG.icaweights) % 1 (true)- Why subtract 1? In MATLAB the first sampleA single value of the signal at one point in time. is number 1 and sits at time zero. So time in seconds = (sample number − 1) ÷ sampling rate.
EEG.data(1, 1:5): the first number selects the channelThe signal recorded from one electrode, as shown in EEGLAB. (row), and the second selects the samples (columns).
How do I write it as code?
Type these lines in the Command Window, one at a time, and compare the output with the comment:
% Basic information
EEG.setname % 'Continuous EEG Data'
EEG.nbchan % 32 channels
EEG.srate % 128 samples per second
EEG.pnts % 30504 samples per channel
(EEG.pnts - 1) / EEG.srate % 238.3047 seconds (same as EEG.xmax)
% The signal: channels x samples
size(EEG.data) % 32 30504
class(EEG.data) % 'single'
EEG.data(1, 1:5) % first 5 samples of channel 1 (microvolts)
% Channel names
{EEG.chanlocs(1:3).labels} % 'FPz' 'EOG1' 'F3'
% First event: type and latency
EEG.event(1).type % 'square'
EEG.event(1).latency % 129.0087 (in samples)
(EEG.event(1).latency - 1) / EEG.srate % 1.0001 (in seconds)
% Empty until ICA is computed
isempty(EEG.icaweights) % 1 (true)- Why subtract 1? In MATLAB the first sample is number 1 and sits at time zero. So time in seconds = (sample number − 1) ÷ sampling rate.
EEG.data(1, 1:5): the first number selects the channel (row), and the second selects the samples (columns).
Which value should I choose?
Suitable values for your analysis goal
There is no value to choose here. These are the main fields you will come back to in every lesson:
| Field | What it stores | Unit | Value in eeglab_data.set |
|---|---|---|---|
EEG.nbchan | Number of channels | channels | 32 |
EEG.srate | Sampling rate | Hz | 128 |
EEG.pnts | Number of samples per channel | samples | 30504 |
EEG.trials | Number of segments (1 = continuous data) | segments | 1 |
EEG.xmin and EEG.xmax | Time of the first and the last sample | seconds | 0 and 238.3047 (last sample) |
EEG.times | Time of each sample | milliseconds | from 0 to 238304.6875 |
EEG.data | The signalValues that change over time, such as the voltage recorded on a channel. itself | microvolts | a 32 × 30504 matrix |
EEG.chanlocs | Name and position of each channel | — | 32 elements |
EEG.event | Events: type and latency | latency in samples | 154 events (80 square and 74 rt) |
EEG.icaweights | ICAA method that separates the recording into independent sources, some brain and some artifact. weights | — | empty |
Which value should I choose?
There is no value to choose here. These are the main fields you will come back to in every lesson:
| Field | What it stores | Unit | Value in eeglab_data.set |
|---|---|---|---|
EEG.nbchan | Number of channels | channels | 32 |
EEG.srate | Sampling rate | Hz | 128 |
EEG.pnts | Number of samples per channel | samples | 30504 |
EEG.trials | Number of segments (1 = continuous data) | segments | 1 |
EEG.xmin and EEG.xmax | Time of the first and the last sample | seconds | 0 and 238.3047 (last sample) |
EEG.times | Time of each sample | milliseconds | from 0 to 238304.6875 |
EEG.data | The signal itself | microvolts | a 32 × 30504 matrix |
EEG.chanlocs | Name and position of each channel | — | 32 elements |
EEG.event | Events: type and latency | latency in samples | 154 events (80 square and 74 rt) |
EEG.icaweights | ICA weights | — | empty |
How do I check it worked?
4 quick checks
size(EEG.data)gives32 30504.(EEG.pnts - 1) / EEG.srategives238.3047, the same asEEG.xmaxand as Epoch end (sec) in the main window (shown rounded as238.305).EEG.event(1).typegives'square', and the converted latency gives about1.0001seconds, matching what you saw in Edit then Event values.numel(EEG.event)gives154, matching the Events line in the main window.
How do I check it worked?
size(EEG.data)gives32 30504.(EEG.pnts - 1) / EEG.srategives238.3047, the same asEEG.xmaxand as Epoch end (sec) in the main window (shown rounded as238.305).EEG.event(1).typegives'square', and the converted latency gives about1.0001seconds, matching what you saw in Edit then Event values.numel(EEG.event)gives154, matching the Events line in the main window.
What mistakes do people make?
5 mistakes and how to avoid them
- Swapping the dimensions. In EEGLAB channels are rows and samples are columns.
EEG.data(:, 1)is all channels at the first sample, not the whole first channel. The whole first channel isEEG.data(1, :). - Reading
latencyas seconds. InEEG.eventthe latency is in samples. Convert it with the formula above, and do not forget to subtract 1. - Forgetting that
EEG.timesis in milliseconds. WhileEEG.xminandEEG.xmaxare in seconds. - Editing
EEGby hand and not telling EEGLAB. If you change a field yourself, runEEG = eeg_checkset(EEG);, then store it with[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);andeeglab redraw. Otherwise the main window may show outdated values. - Mixing up channel and electrodeThe physical sensor placed on the scalp to pick up the signal..
EEG.chanlocs(5)is the fifth channel in the data, and its position is the position of the electrode that recorded it. The channel order in a file does not follow any order on the head.
What mistakes do people make?
- Swapping the dimensions. In EEGLAB channels are rows and samples are columns.
EEG.data(:, 1)is all channels at the first sample, not the whole first channel. The whole first channel isEEG.data(1, :). - Reading
latencyas seconds. InEEG.eventthe latency is in samples. Convert it with the formula above, and do not forget to subtract 1. - Forgetting that
EEG.timesis in milliseconds. WhileEEG.xminandEEG.xmaxare in seconds. - Editing
EEGby hand and not telling EEGLAB. If you change a field yourself, runEEG = eeg_checkset(EEG);, then store it with[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);andeeglab redraw. Otherwise the main window may show outdated values. - Mixing up channel and electrode.
EEG.chanlocs(5)is the fifth channel in the data, and its position is the position of the electrode that recorded it. The channel order in a file does not follow any order on the head.
Your browser doesn't allow saving progress. All lessons are open, but completion marks won't be saved.
Done. Your progress is saved in this browser.UndoWhere can I read more?
2 sources, official docs first
- EEGLAB TutorialDocumentationEEGLAB Data Structures: EEG.event, Event latencies
- EEGLAB TutorialDocumentationExploring event values
Written for EEGLAB 2026.1 · 2026-10-28
Going further
- EEGLAB Tutorial: https://eeglab.org/tutorials/ConceptsGuide/Data_Structures.html (EEGLAB Data Structures: EEG.event, Event latencies)
- EEGLAB Tutorial: https://eeglab.org/tutorials/02_Quickstart/quickstart.html (Exploring event values)
Need help?
Ask, share feedback, or report an error
- Report a scientific error · Needs a GitHub account. Don't have one? Use "Share your thoughts".