What does the path function do in MATLAB / RunMat?
path reads or rewrites the MATLAB search path string that RunMat uses when resolving scripts, functions, and data files. The value mirrors MATLAB's notion of the path: a character row vector whose entries are separated by the platform-specific pathsep character.
How does the path function behave in MATLAB / RunMat?
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.
path Function GPU Execution Behaviour
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 residency in RunMat (Do I need gpuArray?)
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 of using the path function in MATLAB / RunMat
Display the current MATLAB search path
p = path();
disp(p);
Expected output:
/Users/alex/runmat/toolbox:/Users/alex/runmat/user % Actual directories vary by installation
Temporarily replace the MATLAB path
old = path("C:\tools\runmat-addons");
% ... run code that relies on the temporary path ...
path(old); % Restore the previous path
Expected output:
old =
'/Users/alex/runmat/toolbox:/Users/alex/runmat/user'
Append folders to the end of the search path
extra = "C:\projects\analysis";
old = path(path(), extra);
Expected output:
path()
ans =
'C:\tools\runmat-addons;C:\projects\analysis'
Prepend folders ahead of the existing path
extra = "/opt/runmat/toolbox";
old = path(extra, path());
Expected output:
path()
ans =
'/opt/runmat/toolbox:/Users/alex/runmat/toolbox:/Users/alex/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.
FAQ
- Does
pathinclude the current folder? MATLAB automatically searches the current folder (pwd) before consulting the stored path. RunMat follows this rule; the character vector returned bypathreflects the explicit path entries, whilepwdremains 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 orpath(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_PATHenvironment variable. External tooling that readsRUNMAT_PATHwill 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.
See Also
addpath, rmpath, genpath, which, exist
Source & Feedback
- Source:
crates/runmat-runtime/src/builtins/io/repl_fs/path.rs - Found an issue? Open a GitHub ticket with steps to reproduce.