Give a value a name, and MATLAB keeps it until you clear it.
A variable is a name with a value stored under it. The = sign means "store", not "equals": read srate = 500 as "srate gets 500". Watch srate appear in the Workspace. Typing the name alone shows its value.
srate = 500 srate
Once a value has a name, you can use the name in calculations.
seconds = 120 nSamples = srate * seconds
MATLAB worked out nSamples once, when you pressed Enter. If you change srate now, nSamples does not update by itself. Run the calculation again to get the new value.
srate = 250 nSamples nSamples = srate * seconds
A semicolon at the end of a line tells MATLAB to do the work without printing the result. The variable is still made; it just does not echo.
nChans = 32; nChans
Scripts end almost every line with a semicolon. A dataset with 32 channels and 30,000 time points holds 960,000 numbers, and you do not want them all printed.
sub01, n_trials, nSamples.sub-01 as "sub minus 1".EEG, eeg, and Eeg are three different names.mean = 7, mean is a number and the averaging function is hidden until you clear it.sub-01 = 5 Srate # capital S: a different name from srate mean = 7 mean([1 2 3]) # MATLAB now reads this as indexing into the number 7 clear mean mean([1 2 3])
who lists your variables. whos adds the size, memory, and class of each. clear name removes one variable; clear on its own removes them all.
who whos clear seconds clear
Do not mix up clc and clear. clc cleans the screen and keeps your variables. clear deletes the variables and leaves the screen alone.
EEG, and all loaded datasets in ALLEEG. clear removes them from memory, not from your disk. Lab scripts often start with clear so nothing left over from an earlier session sneaks into the analysis.Each box ticks itself when you do it in the practice window. Stuck? "show me" puts a command in the window for you.
The MathWorks, Inc. (2025). MATLAB documentation. https://www.mathworks.com/help/matlab/