View all functions

CategoryIntrospection

What does the who function do in MATLAB / RunMat?

who returns the names of variables that are visible in the active workspace. You can filter the result using wildcard patterns, regular expressions, or by reading directly from MAT-files without loading the data.

How does the who function behave in MATLAB / RunMat?

  • who with 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 -regexp selectors.
  • The result is a column cell array of character vectors (consistent with MATLAB). Empty results return a 0×1 cell array so that idioms like isempty(who(...)) work as expected.

who Function GPU Execution Behaviour

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.

Examples of using the who function in MATLAB / RunMat

List All Workspace Variables

a = 42;
b = rand(3, 2);
names = who;

Expected output (example):

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 (example):

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 (example):

file_names =
  2×1 cell array
    {"alpha"}
    {"beta"}

List Only Global Variables

global shared;
local = 1;
globals = who('global');

Expected output (example):

globals =
  1×1 cell array
    {"shared"}

GPU residency in RunMat (Do I need gpuArray?)

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.

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.

See Also

whos, which, class, size, load, save, gpuArray, gather

Source & Feedback