Station 1 · Lesson 6
Merging & selecting data
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
Many experiments record each participantThe person whose data were recorded in the study. in several runs, with a break in between. To analyze them together, you merge them into one datasetOne EEG data file loaded in EEGLAB together with its information.. Sometimes you need the opposite: only one part of the recording. But how does EEGLAB know that the signalValues that change over time, such as the voltage recorded on a channel. was broken at the join?
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
The answer is a special eventA marker in the recording that flags a moment of interest, such as a stimulus. called boundary. EEGLAB adds it automatically at every join or cut, and later filteringApplying a filter to the data. and epoching respect it. So that you need no new data, we practice on eeglab_data.set: we split it into two parts, merge them again, and see where the boundary event appears.
In real experiments, each participant is often recorded in several runs. For example, the raw version of the station 8 data on OpenNeuro (ds002680) has two sessions of 12 or 13 runs for each participant. The ready copy we use in station 8 has already been prepared, with one file per conditionAn experimental situation compared with others, such as familiar vs unfamiliar..
Why do I need this step?
The answer is a special event called boundary. EEGLAB adds it automatically at every join or cut, and later filtering and epoching respect it. So that you need no new data, we practice on eeglab_data.set: we split it into two parts, merge them again, and see where the boundary event appears.
In real experiments, each participant is often recorded in several runs. For example, the raw version of the station 8 data on OpenNeuro (ds002680) has two sessions of 12 or 13 runs for each participant. The ready copy we use in station 8 has already been prepared, with one file per condition.
How do I do it in EEGLAB?
23 steps in the menus
1. Cut the first part
- With
eeglab_data.setopen as dataset 1, open Edit then Select data. - In the Time range [min max] (s) row, type
0 120. Leave the checkbox under on->remove these in the same row unticked. - Click OK. In the What do you want to do with the new dataset? window, type
D1 part 1in Name it:, then click OK. - The first line of the main window is now
#2: D1 part 1, and Frames per epoch shows 15361.
2. Cut the second part
- From the Datasets , choose
Dataset 1:Continuous EEG Data. Always cut from the original, not from part 1. - Open Edit then Select data again.
- Type the same range
0 120in Time range [min max] (s), and this time tick the checkbox under on->remove these. EEGLAB now removes the first 120 seconds and keeps the rest. - Click OK, and name the new dataset
D1 part 2. - The main window shows
#3: D1 part 2and 15143 samples.
Using the same range with and without the checkbox makes sure that the two parts do not overlap and that no sampleA single value of the signal at one point in time. is lost between them.
3. Merge the two parts
- Open Edit then Append datasets.
- In Dataset indices to merge, type
2 3. The order matters: the first dataset comes first in time. - Leave Preserve ICA weights of the first dataset ? unticked, and click OK.
- EEGLAB suggests the name
Merged datasets. Change it toD1 merged, then click OK. - The main window shows
#4: D1 merged: 30504 samples like the original, and Events shows 155 instead of 154.
The Command Window may print Warning: duplicate boundary event removed. This is normal: each part already had a boundary at its cut edge, and EEGLAB keeps only one at the join.
4. Find the join
- With
D1 mergedas the current dataset, open Plot then Channel data (scroll). - In the box between the two arrows at the bottom of the window, type
118and press Enter. - At 120 seconds you see a thick red line labelled
boundary. This is the extra event: number 155.
5. Select the data around one event type
- Go back to
Dataset 1:Continuous EEG Datain the Datasets menu. - Open Edit then Select data using events. The window Remove data portions around events - pop_rmdat() opens.
- In Event type(s) ([]=all), type
square. - In Time limits [start, end] in sec., type
-0.5 1: from half a second before eachsquareevent to one second after it. - Leave the list on Keep selected, and click OK. Name the dataset
D1 around square. - 15336 samples remain (about 120 seconds), and Events shows 234: all 154 original events, plus 80
boundaryevents, one at each removed part.
How do I do it in EEGLAB?
1. Cut the first part
- With
eeglab_data.setopen as dataset 1, open Edit then Select data. - In the Time range [min max] (s) row, type
0 120. Leave the checkbox under on->remove these in the same row unticked. - Click OK. In the What do you want to do with the new dataset? window, type
D1 part 1in Name it:, then click OK. - The first line of the main window is now
#2: D1 part 1, and Frames per epoch shows 15361.
2. Cut the second part
- From the Datasets menu, choose
Dataset 1:Continuous EEG Data. Always cut from the original, not from part 1. - Open Edit then Select data again.
- Type the same range
0 120in Time range [min max] (s), and this time tick the checkbox under on->remove these. EEGLAB now removes the first 120 seconds and keeps the rest. - Click OK, and name the new dataset
D1 part 2. - The main window shows
#3: D1 part 2and 15143 samples.
Using the same range with and without the checkbox makes sure that the two parts do not overlap and that no sample is lost between them.
3. Merge the two parts
- Open Edit then Append datasets.
- In Dataset indices to merge, type
2 3. The order matters: the first dataset comes first in time. - Leave Preserve ICA weights of the first dataset ? unticked, and click OK.
- EEGLAB suggests the name
Merged datasets. Change it toD1 merged, then click OK. - The main window shows
#4: D1 merged: 30504 samples like the original, and Events shows 155 instead of 154.
The Command Window may print Warning: duplicate boundary event removed. This is normal: each part already had a boundary at its cut edge, and EEGLAB keeps only one at the join.
4. Find the join
- With
D1 mergedas the current dataset, open Plot then Channel data (scroll). - In the box between the two arrows at the bottom of the window, type
118and press Enter. - At 120 seconds you see a thick red line labelled
boundary. This is the extra event: number 155.
5. Select the data around one event type
- Go back to
Dataset 1:Continuous EEG Datain the Datasets menu. - Open Edit then Select data using events. The window Remove data portions around events - pop_rmdat() opens.
- In Event type(s) ([]=all), type
square. - In Time limits [start, end] in sec., type
-0.5 1: from half a second before eachsquareevent to one second after it. - Leave the list on Keep selected, and click OK. Name the dataset
D1 around square. - 15336 samples remain (about 120 seconds), and Events shows 234: all 154 original events, plus 80
boundaryevents, one at each removed part.
How do I write it as code?
The same steps in 29 lines of MATLAB
% Start EEGLAB and load the sample dataset as dataset 1
[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');
% Part 1: keep the first 120 seconds (dataset 2)
EEG = pop_select(ALLEEG(1), 'time', [0 120]);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 part 1', 'gui', 'off');
% Part 2: remove the same 120 seconds and keep the rest (dataset 3)
EEG = pop_select(ALLEEG(1), 'rmtime', [0 120]);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 part 2', 'gui', 'off');
% Append datasets 2 and 3 (dataset 4)
EEG = pop_mergeset(ALLEEG, [2 3], 0);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 merged', 'gui', 'off');
[ALLEEG.pnts] % 30504 15361 15143 30504
isequal(ALLEEG(4).data, ALLEEG(1).data) % 1: same signal as the original
eeg_eventtypes(EEG) % square 80, rt 74, boundary 1
EEG.event(eeg_findboundaries(EEG)).latency % 15361.5: between samples 15361 and 15362
% Keep only the data from -0.5 to 1 s around each square event (dataset 5)
EEG = pop_rmdat(ALLEEG(1), {'square'}, [-0.5 1], 0);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 around square', 'gui', 'off');
EEG.pnts % 15336
numel(eeg_findboundaries(EEG)) % 80
eeglab redraw;'time'keeps the range, and'rmtime'removes it. They are the checkbox under on->remove these, unticked and ticked.pop_mergeset(ALLEEG, [2 3], 0)merges dataset 2, then 3. The final zero means: do not keep the ICAA method that separates the recording into independent sources, some brain and some artifact. weights.- The last number in
pop_rmdatis the list in the window:0means Keep selected, and1means Remove selected.
How do I write it as code?
% Start EEGLAB and load the sample dataset as dataset 1
[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');
% Part 1: keep the first 120 seconds (dataset 2)
EEG = pop_select(ALLEEG(1), 'time', [0 120]);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 part 1', 'gui', 'off');
% Part 2: remove the same 120 seconds and keep the rest (dataset 3)
EEG = pop_select(ALLEEG(1), 'rmtime', [0 120]);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 part 2', 'gui', 'off');
% Append datasets 2 and 3 (dataset 4)
EEG = pop_mergeset(ALLEEG, [2 3], 0);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 merged', 'gui', 'off');
[ALLEEG.pnts] % 30504 15361 15143 30504
isequal(ALLEEG(4).data, ALLEEG(1).data) % 1: same signal as the original
eeg_eventtypes(EEG) % square 80, rt 74, boundary 1
EEG.event(eeg_findboundaries(EEG)).latency % 15361.5: between samples 15361 and 15362
% Keep only the data from -0.5 to 1 s around each square event (dataset 5)
EEG = pop_rmdat(ALLEEG(1), {'square'}, [-0.5 1], 0);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, ...
'setname', 'D1 around square', 'gui', 'off');
EEG.pnts % 15336
numel(eeg_findboundaries(EEG)) % 80
eeglab redraw;'time'keeps the range, and'rmtime'removes it. They are the checkbox under on->remove these, unticked and ticked.pop_mergeset(ALLEEG, [2 3], 0)merges dataset 2, then 3. The final zero means: do not keep the ICA weights.- The last number in
pop_rmdatis the list in the window:0means Keep selected, and1means Remove selected.
Which value should I choose?
Suitable values for your analysis goal
| What you want | Menu | What to type |
|---|---|---|
| One continuous part of the recording | Edit then Select data | The range in seconds in Time range [min max] (s), checkbox unticked. |
| Remove one continuous part (start, end or a break) | Edit then Select data | The same range, with the checkbox under on->remove these ticked. |
| The data around one event typeThe name or code that identifies what kind of event it is. | Edit then Select data using events | The event type, the limits in seconds around it, and Keep selected. |
| Remove the data around an event, such as a TMS pulse that saturates the amplifier | Edit then Select data using events | The event type, short limits around it, and Remove selected. The official tutorial gives this example. |
| Several runs of one participant in one dataset | Edit then Append datasets | The dataset numbers in the order they were recorded. |
When to merge? Usually right after import and channelThe signal recorded from one electrode, as shown in EEGLAB. locations, before filtering and ICA. ICA needs a lot of data, and the runs of one session share the same electrodes.
Which value should I choose?
| What you want | Menu | What to type |
|---|---|---|
| One continuous part of the recording | Edit then Select data | The range in seconds in Time range [min max] (s), checkbox unticked. |
| Remove one continuous part (start, end or a break) | Edit then Select data | The same range, with the checkbox under on->remove these ticked. |
| The data around one event type | Edit then Select data using events | The event type, the limits in seconds around it, and Keep selected. |
| Remove the data around an event, such as a TMS pulse that saturates the amplifier | Edit then Select data using events | The event type, short limits around it, and Remove selected. The official tutorial gives this example. |
| Several runs of one participant in one dataset | Edit then Append datasets | The dataset numbers in the order they were recorded. |
When to merge? Usually right after import and channel locations, before filtering and ICA. ICA needs a lot of data, and the runs of one session share the same electrodes.
How do I check it worked?
5 quick checks
- The Datasets menu lists five datasets:
Continuous EEG Data,D1 part 1,D1 part 2,D1 mergedandD1 around square. - Frames per epoch for the first four: 30504, 15361, 15143 and 30504.
D1 mergedhas 155 events,eeg_eventtypesshowsboundary 1, and you see it as a red line at 120 seconds in the scroll window.isequal(ALLEEG(4).data, ALLEEG(1).data)gives1: merging gave back exactly the original signal.D1 around squarehas 15336 samples and 80boundaryevents.
Nothing in this lesson is saved to disk. Delete datasets 2 to 5 from memory with Edit then Delete dataset(s) from memory before the next lesson, or close EEGLAB.
The Methods sentence below is for real use, when you merge several runs of one participant, not for the two-halves exercise in this lesson.
How do I check it worked?
- The Datasets menu lists five datasets:
Continuous EEG Data,D1 part 1,D1 part 2,D1 mergedandD1 around square. - Frames per epoch for the first four: 30504, 15361, 15143 and 30504.
D1 mergedhas 155 events,eeg_eventtypesshowsboundary 1, and you see it as a red line at 120 seconds in the scroll window.isequal(ALLEEG(4).data, ALLEEG(1).data)gives1: merging gave back exactly the original signal.D1 around squarehas 15336 samples and 80boundaryevents.
Nothing in this lesson is saved to disk. Delete datasets 2 to 5 from memory with Edit then Delete dataset(s) from memory before the next lesson, or close EEGLAB.
The Methods sentence below is for real use, when you merge several runs of one participant, not for the two-halves exercise in this lesson.
What mistakes do people make?
5 mistakes and how to avoid them
- Merging datasets with a different number of channels or sampling rateThe number of samples recorded per second on each channel.. Edit then Append datasets stops with the error
The two datasets must have the same number of channelsorThe two datasets must have the same sampling rate. Make channels and rate match before merging. - Merging datasets with the same number of channels in a different order. EEGLAB checks the number only, not the names. The
Czsignal of one run can end up under the namePzof another, with no warning. Compare{EEG.chanlocs.labels}in both datasets before merging. - Deleting or ignoring
boundaryevents in an old script. EEGLAB filters each part between twoboundaryevents on its own, and epoching skips any epoch that crosses a join. If you delete them, or filterEEG.datadirectly with a MATLAB function, the join is treated as a continuous signal and a false jump appears. - Forgetting that every cut and every merge is a new dataset. Edit then Select data and Edit then Append datasets add a new dataset to
ALLEEG, and the original stays as it is. Give each copy a clear name, and look at the first line of the main window before each step. - Cutting from part 1 instead of the original. In step 2, if
D1 part 1is still the current dataset, you remove the first 120 seconds of it, and almost nothing is left. Go back to dataset 1 first.
What mistakes do people make?
- Merging datasets with a different number of channels or sampling rate. Edit then Append datasets stops with the error
The two datasets must have the same number of channelsorThe two datasets must have the same sampling rate. Make channels and rate match before merging. - Merging datasets with the same number of channels in a different order. EEGLAB checks the number only, not the names. The
Czsignal of one run can end up under the namePzof another, with no warning. Compare{EEG.chanlocs.labels}in both datasets before merging. - Deleting or ignoring
boundaryevents in an old script. EEGLAB filters each part between twoboundaryevents on its own, and epoching skips any epoch that crosses a join. If you delete them, or filterEEG.datadirectly with a MATLAB function, the join is treated as a continuous signal and a false jump appears. - Forgetting that every cut and every merge is a new dataset. Edit then Select data and Edit then Append datasets add a new dataset to
ALLEEG, and the original stays as it is. Give each copy a clear name, and look at the first line of the main window before each step. - Cutting from part 1 instead of the original. In step 2, if
D1 part 1is still the current dataset, you remove the first 120 seconds of it, and almost nothing is left. Go back to dataset 1 first.
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.UndoHow do I write it in my paper?
A Methods template: edit the data, settings and versions to match what you ran
A template: edit the data, settings and versions to match what you ran.
Data from the [N] recording runs were concatenated into a single continuous dataset (pop_mergeset, EEGLAB 2026.1), with boundary events marking the joins.How do I write it in my paper?
A template: edit the data, settings and versions to match what you ran.
Data from the [N] recording runs were concatenated into a single continuous dataset (pop_mergeset, EEGLAB 2026.1), with boundary events marking the joins.Where can I read more?
4 sources, official docs first
- EEGLAB TutorialDocumentationEEGLAB data structures: Event boundaries
- EEGLAB TutorialDocumentation7. Extract Data Epochs: Selecting a subset of data epochs (Edit > Select data)
- EEGLAB TutorialDocumentationb. Remove bad data by visual inspection: Rejecting bad portions of data surrounding events
- pop_mergeset (EEGLAB function help)Documentationhelp pop_mergeset
Written for EEGLAB 2026.1 · 2026-10-28
Going further
- EEGLAB Tutorial: https://eeglab.org/tutorials/ConceptsGuide/Data_Structures.html (EEGLAB data structures: Event boundaries)
- EEGLAB Tutorial: https://eeglab.org/tutorials/07_Extract_epochs/Extracting_Data_Epochs.html (7. Extract Data Epochs: Selecting a subset of data epochs (Edit > Select data))
- EEGLAB Tutorial: https://eeglab.org/tutorials/06_RejectArtifacts/Scrolling_data.html (b. Remove bad data by visual inspection: Rejecting bad portions of data surrounding events)
- pop_mergeset (EEGLAB function help): https://sccn.ucsd.edu/~arno/eeglab/auto/pop_mergeset.html (help pop_mergeset)
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".