which — Resolve which variable, builtin, file, or class matches a given name.
which name observes the current dynamic-call name environment without invoking a function or loading a native module. The runtime's workspace, semantic-function, builtin, native-module, and search-path owners supply the ordered candidates; which formats them.
Syntax
result = which(name)
result = which(name, option)
result = which(option, name)
results = which("-all", name)Inputs
name- Type
StringScalar- Required
- Yes
- Description
- Name to resolve.
option- Type
StringScalar- Required
- No
- Description
- Optional mode filter (-all|-builtin|-var|-file).
option- Type
StringScalar- Required
- Yes
- Description
- Mode filter (-all|-builtin|-var|-file).
Returns
result- Type
StringScalar- Description
- Single resolution result string.
results- Type
Any- Description
- All matching resolution strings (cell array of char rows).
Errors
- When
- No input arguments are provided.
- Message
which: not enough input arguments
- When
- More than one name argument is provided.
- Message
which: too many input arguments
- When
- Name argument is not a char row or string scalar.
- Message
which: name must be a character vector or string scalar
Behavior and placement
Names can be supplied as character vectors or string scalars. Calling which with no name raises which: not enough input arguments.
which name without options returns the first candidate observed for an ordinary dynamic-name call. Workspace variables precede function candidates. Registered constructors can precede native, semantic, and source fallbacks; an exact executable builtin binding wins a same-name constructor collision. Otherwise the runtime observes native modules, semantic functions (including selected local/private bindings), .m source, and builtin bindings in call-route order. Presentation-only class folders and other files follow executable candidates.
which(name, "-all") (or which("-all", name)) returns a cell array of the selected candidate followed by ordered shadowed candidates, without duplicate displayed entries. When nothing matches, even -all returns the character row '<name>' not found. Ordinary lookup stops at the first match; -all continues through later candidates.
which(..., "-builtin") restricts the search to builtin functions. "-var" restricts to workspace variables, and "-file" restricts the search to files, classes, and folders.
Package-qualified names like pkg.func map to +pkg folders in the current path search. Registered class constructors and public static methods are observed where their dynamic-call routes apply; class candidates also include @ClassName folders and .m files containing classdef. An unqualified instance-method call can depend on receiver arguments, so a bare name alone cannot identify every method dispatch.
Relative paths are resolved against the current working directory. Absolute paths and paths beginning with ~ or drive letters are honoured directly.
which parses text and observes runtime/path metadata on the host. A GPU tensor has a numeric descriptor, not a character or string representation, so it is rejected as a name or option before a provider download. Results are host-resident character arrays or cell arrays.
Named feval has a distinct semantic-before-builtin route. which reports the ordinary dynamic-name route; it does not claim that the same ordering applies to every call form.
Examples and displayed results
Finding a built-in function's implementation
which("sin")
Expected display: built-in (RunMat builtin: sin)
Checking if a workspace variable shadows a builtin
answer = 42;
which("answer")
Expected display: 'answer' is a variable.
Listing all matches on the path (illustrative when both implementations exist; order follows the active dynamic-call environment)
which("sum", "-all")
Expected display: {
[1,1] = built-in (RunMat builtin: sum)
[2,1] = //runmat/stdlib/sum.m
}
Locating a script or function file
which("helpers/process_data")
Expected display: //projects/runmat/helpers/process_data.m
Restricting the search to variables
which("-var", "velocity")
Expected display: 'velocity' is a variable.
Restricting the search to files
which("fft", "-file")
Expected display: //runmat/overrides/fft.m
Examples
resolve a builtin
p = which('sin')observe a workspace variable
resolution_which_example_value = 42; p = which('resolution_which_example_value')report no match with -all
p = which('__runmat_which_documentation_no_match__', '-all')Using which with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how which changes the result.
Run a small which example, explain the result, then change one input and compare the output.
FAQ
What happens when nothing is found?⌄
which returns the character vector '<name>' not found., including when -all is requested.
Are method lookups supported?⌄
Registered constructors and public static methods are included when a dynamic-name call can select them. @Class folders and .m files containing classdef are reported as file candidates. Unqualified instance methods still require a receiver to determine dispatch.
Does which canonicalise paths?⌄
Yes. RunMat reports canonical absolute paths where possible; when canonicalisation fails, the original path is returned.
Can I combine -all with other options?⌄
Yes. For example, which("plot", "-all", "-file") lists every file-based implementation without reporting builtins or variables.
Does the search respect RUNMAT_PATH / MATLABPATH?⌄
Yes. The directory list mirrors the logic used by other REPL filesystem builtins.
What about Simulink models or Java classes?⌄
The general path search does not append .slx, .mdl, or .class extensions automatically. An explicitly spelled path may match if the VFS exposes that exact file; no Simulink or Java class interpretation is implied.
Are duplicate results filtered?⌄
Yes. The first occurrence of each unique path is returned.
Is the lookup case sensitive?⌄
Option flags are decoded case-insensitively. File and directory candidates use their constructed spelling and the active VFS, so case behavior depends on that filesystem; cross-platform case-insensitive lookup is not guaranteed.
Does which gather GPU values?⌄
No. GPU tensor descriptors are numeric rather than text, so a GPU tensor supplied as the name or an option is rejected before any provider download.
Related Introspection functions
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · func2str · functions · get.p · getcallinfo · getmethod · inputname · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · who · whos
Source you can read
Every RunMat function's source is public. Read exactly how which is executed, line by line, in Rust.
- View the source for which in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.