who — List variable names in workspaces or MAT-files using MATLAB-compatible filtering forms.
who returns visible variable names in the current workspace or in MAT-files, with MATLAB-compatible wildcard, regexp, and file-targeted query options.
Syntax
names = who()
names = who(selector, ...)
names = who("-file", filename, selector, ...)
names = who("-regexp", pattern, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
selector | StringScalar | Variadic | — | Name filters, wildcard patterns, or options. |
file_kw | StringScalar | Yes | "-file" | File mode option. |
filename | StringScalar | Yes | — | MAT-file path. |
regexp_kw | StringScalar | Yes | "-regexp" | Regexp mode option. |
pattern | StringScalar | Variadic | — | Regular-expression patterns. |
Returns
| Name | Type | Description |
|---|---|---|
names | Any | Cell array of matching variable names. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | The '-file' option is provided without a filename. | who: '-file' requires a filename |
| — | The '-file' option is provided more than once. | who: '-file' may only be specified once |
| — | The '-regexp' option is provided without patterns. | who: '-regexp' requires at least one pattern |
| — | The '-regexp' option receives only empty patterns. | who: '-regexp' requires non-empty pattern strings |
| — | A regexp pattern fails to compile. | who: invalid regular expression |
| — | An unsupported option token is provided. | who: unsupported option |
| — | Filename argument is not a char row or string scalar. | who: filename must be a character vector or string scalar |
| — | A selector cell contains a non-string-like element. | who: selection cells must contain string or character scalars |
| — | Selector argument is not a char array/string/string array/cell thereof. | who: selections must be character vectors, string scalars, string arrays, or cell arrays of those types |
| — | Wildcard selector pattern fails to parse. | who: invalid pattern |
How who works
whowith no arguments lists every variable in the current workspace, sorted alphabetically.who pattern1 pattern2 ...accepts character vectors or string scalars with MATLAB wildcard syntax (*,?,[abc]). Any variable name that matches at least one pattern is returned.who('-regexp', expr1, expr2, ...)keeps names that match any of the supplied regular expressions.who('global')lists only global variables in the active workspace.who('-file', filename, ...)inspects the variables stored in a MAT-file. You can combine this option with explicit names or-regexpselectors.- The result is a column cell array of character vectors (consistent with MATLAB). Empty results return a
0×1cell array so that idioms likeisempty(who(...))work as expected.
Does RunMat run who on the GPU?
who is a pure introspection builtin that runs on the CPU. When a variable is a gpuArray, RunMat leaves it resident on the device and reports its name without triggering any device-to-host copies. Only scalar selector arguments are gathered if they are stored on the GPU.
GPU memory and residency
No. who never requires you to gather data or move arrays between the host and GPU. It simply reports variable names, regardless of residency. Use gpuArray or gather only when you explicitly need to control where data lives.
Examples
List All Workspace Variables
a = 42;
b = rand(3, 2);
names = whoExpected output:
names =
2×1 cell array
{"a"}
{"b"}Filter With Wildcard Patterns
alpha = 1;
beta = 2;
names = who("a*")Expected output:
names =
1×1 cell array
{"alpha"}Use Regular Expressions
x1 = rand;
x2 = rand;
matches = who('-regexp', '^x\d$')Expected output:
matches =
2×1 cell array
{"x1"}
{"x2"}Inspect Variables Stored In A MAT-File
save('snapshot.mat', 'alpha', 'beta')
file_names = who('-file', 'snapshot.mat')Expected output:
file_names =
2×1 cell array
{"alpha"}
{"beta"}List Only Global Variables
global shared;
local = 1;
globals = who('global')Expected output:
globals =
1×1 cell array
{"shared"}Using who with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how who changes the result.
Run a small who example, explain the result, then change one input and compare the output.
FAQ
What type does who return?⌄
A column cell array of character vectors, matching MATLAB behaviour.
Are the names sorted?⌄
Yes. Results are sorted alphabetically so that diffs are deterministic.
Can I mix wildcard patterns and -regexp?⌄
Yes. The final result includes any name matched by either the wildcard selectors or the regular expressions.
What happens if no variables match?⌄
You receive a 0×1 cell array. You can call isempty on it to check for an empty result.
Can I call who('-file', ...) on large MAT-files?⌄
Yes. The builtin reads just enough metadata to enumerate variable names; it does not load the data into the workspace.
Related Introspection functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how who is executed, line by line, in Rust.
- View the source for who in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.