← Digital Concepts 8 lessons

Intro to MATLAB

The MATLAB you need before EEGLAB, one short lesson at a time.

Lesson 1

The Command Window

The prompt, arithmetic, ans, clc, the up arrow, and how to read an error message.

>>ansclc%
Lesson 2

Variables and the Workspace

Naming values, the semicolon, naming rules, and seeing and clearing what MATLAB holds in memory.

=;whowhosclear
Lesson 3

Folders and the Path

Where MATLAB looks for files and functions, and how to put EEGLAB on the path.

pwdcdlsaddpathwhicheeglab
Lesson 4

Characters and Strings

Character vectors and strings, joining text, and building file names with sprintf.

'text'"text"sprintfstrcmp
Lesson 5

Arrays and Matrices

Vectors and matrices, counting from 1, the colon, and why EEG data is a channels-by-time matrix.

[ ]x(end)A(2, :)mean(x, 2).*
Lesson 6

Structs and the EEG Variable

Structs and fields, then a loaded dataset: EEG.srate, EEG.data, channel labels, and events.

s.fieldpop_loadsetEEG.dataEEG.chanlocs
Lesson 7

Functions

Inputs and outputs, help, the EEG = pop_...(EEG, ...) pattern, and writing a function file.

f(x)[a, b] = f(x)helpfunction
Lesson 8

Loops and Scripts

for loops, cell arrays of participant IDs, if, and a script that filters every participant.

for{ }ifscript

How each lesson works

What the practice window is, and is not

It is a small model of MATLAB that runs in your browser. It understands the commands in these lessons, gives MATLAB's error messages for the common mistakes, and has a pretend computer with an EEGLAB folder and three datasets. The data are simulated: 32 channels, 60 seconds at 500 Hz. It does not draw plots or open the EEGLAB window, and pop_eegfiltnew records the filter without changing the numbers.

To follow along in real MATLAB, download EEGLAB from the EEGLAB download page, unzip it into your Documents/MATLAB folder, and start at lesson 3 to put it on the path. Your version number will differ from the eeglab2025.1 used here.

Where this leads

The ERP Pipeline series picks up from here: filtering, re-referencing, epoching, artifact detection, and measurement, each with the EEGLAB or ERPLAB command used in lab.