Intro to MATLAB · for EEGLAB lesson 1 / 8

The Command Window

Type a command, press Enter, and MATLAB answers.

1What you are looking at

MATLAB opens with several panels. The practice window on the right copies the three you need first:

  • Command Window, in the middle: where you type. MATLAB answers underneath.
  • Workspace, on the right: every variable MATLAB is holding in memory right now.
  • Current Folder, on the left: the folder MATLAB is working in, and the files inside it.

Your copy of MATLAB may arrange them differently. A fourth panel, the Editor, is where scripts are written. It shows up in lesson 7.

2The prompt

The >> in the Command Window is the prompt. It means MATLAB is waiting for you. Type a command after it, press Enter, and the answer appears below. Try these, either by typing them or with the Run buttons:

2 + 3
500 * 2  # 2 seconds of EEG recorded at 500 samples per second
10 / 4

MATLAB uses * for multiply, / for divide, and ^ for a power. It follows the usual order of operations, so add parentheses when you mean something else:

2 ^ 10
(0.1 + 30) / 2

3ans holds the last answer

When you calculate something without giving the result a name, MATLAB puts it in a variable called ans. Look at the Workspace: ans appeared there after your first command. Each new unnamed result replaces the old one, and you can use ans in the next command.

500 * 60  # samples in one minute at 500 Hz
ans * 5  # samples in five minutes

ans is fine for a quick check. For anything you want to keep, give it a name of your own, which is the next lesson.

4Clearing the screen and repeating a command

clc wipes the text in the Command Window. It only cleans the screen. Everything in the Workspace stays.

clc

Click in the command line and press the up arrow (↑) to bring back what you typed before. Press it again to go further back. You can edit the line before pressing Enter, which saves retyping a long command that had one typo.

5Error messages

When MATLAB cannot make sense of a command, it prints a message in red and does nothing else. Nothing is broken. Read the message, fix the line, and run it again.

5 +
eegdata

The first is missing a number after the +. The second asks for something called eegdata, and MATLAB has no variable or function by that name. "Unrecognized function or variable" is the error you will see most. It almost always means a typo, a variable you have not made yet, or a function MATLAB cannot find (lesson 3).

6Comments

Anything after a % is a comment. MATLAB skips it; it is there for the person reading.

500 * 2   % samples in two seconds
In EEGLAB. Each menu choice you make in EEGLAB runs a MATLAB command, the same kind you are typing here. Once you can read those commands, you can repeat a whole analysis by running them again, and that is what the later lessons build toward.

Your turn

Each box ticks itself when you do it in the practice window. Stuck? "show me" puts a command in the window for you.

References

The MathWorks, Inc. (2025). MATLAB documentation. https://www.mathworks.com/help/matlab/