path — Query or replace the active MATLAB search path string.
path reads or updates the path string used for function/script resolution, preserving MATLAB-compatible path-separator and replacement semantics.
Syntax
oldpath = path()
oldpath = path(path1)
oldpath = path(path1, path2)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
path1 | StringScalar | Yes | — | Replacement path string. |
path1 | StringScalar | Yes | — | Left path fragment. |
path2 | StringScalar | Yes | — | Right path fragment. |
Returns
| Name | Type | Description |
|---|---|---|
oldpath | StringScalar | Previous search path string. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | Path arguments are not character vectors or string scalars. | path: arguments must be character vectors or string scalars |
| — | More than two positional arguments are provided. | path: too many input arguments |
How path works
path()(no inputs) returns the current search path as a character row vector. Each directory is separated bypathsep(;on Windows,:on Linux/macOS). The current working folder (pwd) is implicit and therefore is not included in the string.old = path(newPath)replaces the stored path withnewPathand returns the previous value so it can be restored later.newPathmay be a character row vector, a string scalar, or a 1-by-N double array of character codes. Whitespace at the ends of entries is preserved, matching MATLAB.old = path(path1, path2)sets the path topath1followed bypath2. When both inputs are non-empty they are joined withpathsep; empty inputs are ignored sopath("", path2)simply appliespath2.- All inputs must be character vectors or string scalars. Single-element string arrays are accepted. Multirow char arrays, multi-element string arrays, numeric arrays that cannot be interpreted as character codes, and other value types raise
path: arguments must be character vectors or string scalars. - Calling
path("")clears the stored path while leavingpwdas the highest-priority location, just like MATLAB. The new value is stored in-process and mirrored to theRUNMAT_PATHenvironment variable, soexist,which,dir, and other filesystem-aware builtins observe the change immediately.
Does RunMat run path on the GPU?
path operates entirely on host-side state. If an argument lives on the GPU, RunMat gathers it back to the CPU before validation. No acceleration provider hooks are required and no GPU kernels are launched.
GPU memory and residency
No. The MATLAB path is a host-only configuration. RunMat automatically gathers any gpuArray text inputs, applies the request on the CPU, and returns the result as a character array. Explicitly creating gpuArray strings provides no benefit.
Examples
Display the current MATLAB search path
p = path();
disp(p)Expected output:
//runmat/toolbox://runmat/userTemporarily replace the MATLAB path
old = path("//runmat-addons");
% ... run code that relies on the temporary path ...
path(old); % Restore the previous pathExpected output:
old =
'//runmat/toolbox://runmat/user'Append folders to the end of the search path
extra = "//projects/analysis";
path(path(), extra);
path()Expected output:
ans =
'//runmat/toolbox://runmat/user://projects/analysis'Prepend folders ahead of the existing path
extra = "/opt/runmat/toolbox";
path(extra, path());
path()Expected output:
ans =
'/opt/runmat/toolbox://runmat/toolbox://runmat/user'Combine generated folder lists
tooling = genpath("submodules/tooling");
old = path(tooling, path())Expected output:
% The directories returned by genpath now appear ahead of the previous path entries.Using path with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how path changes the result.
Run a small path example, explain the result, then change one input and compare the output.
FAQ
Does path include the current folder?⌄
MATLAB automatically searches the current folder (pwd) before consulting the stored path. RunMat follows this rule; the character vector returned by path reflects the explicit path entries, while pwd remains an implicit priority.
Can I clear the path completely?⌄
Yes. Call path("") to remove all explicit entries. The current folder is still searched first.
How do I append to the path without losing the existing value?⌄
Use path(path(), newEntry) to append or path(newEntry, path()) to prepend. Both return the previous value so you can restore it later.
Where is the path stored?⌄
RunMat keeps the value in memory and updates the RUNMAT_PATH environment variable. External tooling that reads RUNMAT_PATH will therefore observe the latest configuration.
Do other builtins see the new path immediately?⌄
Yes. exist, which, run, and other filesystem-aware builtins query the shared path state on each call.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fullfile · genpath · getenv · ls · mkdir · movefile · pwd · rmdir · rmpath · run · savepath · setenv · tempdir · tempname
Tabular
csvread · csvwrite · dlmread · dlmwrite · readmatrix · writematrix
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite
Json
Http
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how path is executed, line by line, in Rust.
- View the source for path 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.