What does the rmpath function do in MATLAB / RunMat?
rmpath removes folders from the MATLAB search path that RunMat consults when resolving functions, scripts, classes, and data files. The change is applied immediately and mirrors MATLAB semantics, including error reporting when a folder is missing or not currently on the path.
How does the rmpath function behave in MATLAB / RunMat?
- Folder arguments may be character vectors, string scalars, string arrays, or cell arrays of character vectors or strings. Multi-row char arrays contribute one folder per row (trailing padding is stripped).
- Multiple folders can be passed inside a single argument using the platform path separator (
:on Linux/macOS,;on Windows); this is compatible withgenpathoutput. - RunMat accepts any ordering of arguments. Each requested folder is removed at most once even if it appears repeatedly.
- Inputs are resolved to absolute, normalised paths. Relative inputs are interpreted relative to the current working directory, and
~expands to the user’s home directory. - Folders must exist and must currently be present on the MATLAB path. RunMat raises
rmpath: folder '<name>' not foundwhen a directory cannot be located, orrmpath: folder '<name>' not on search pathwhen the directory exists locally but is absent from the current search path. rmpathreturns the previous path so callers can restore it later viapath(old), matching RunMat’saddpathandpathbuiltins.
rmpath Function GPU Execution Behaviour
rmpath manipulates host-side configuration. If any input value resides on the GPU, RunMat gathers it back to the host before parsing. No acceleration provider hooks or kernels are involved.
GPU residency in RunMat (Do I need gpuArray?)
No. rmpath operates entirely on CPU-side strings. Supplying gpuArray text inputs offers no benefit—RunMat gathers them automatically before processing.
Examples of using the rmpath function in MATLAB / RunMat
Removing a single folder from the MATLAB search path
old = rmpath("util/toolbox");
disp(old);
path();
Expected output:
old =
'/Users/you/runmat/toolbox:util/toolbox'
% The folder util/toolbox no longer appears in the active search path.
Removing multiple folders at once
rmpath("shared/filters", "shared/signal");
path();
Expected output:
% shared/filters and shared/signal are both removed from the MATLAB path.
Removing folders produced by genpath
tree = genpath("third_party/toolchain");
rmpath(tree);
Expected output:
% Every directory returned by genpath is pruned from the search path.
Removing folders specified in a cell array
folders = {'src/algorithms', 'src/visualization'};
rmpath(folders{:});
path();
Expected output:
% Both folders are removed from the MATLAB search path.
Capturing and restoring the previous path after removal
old = rmpath("analysis/utilities");
% ... run experiments ...
path(old); % Restore the previous path
path();
Expected output:
% The original search path is restored when you call path(old).
Handling attempts to remove folders that are not on the path
rmpath("nonexistent/toolbox");
Expected result:
Error: rmpath: folder 'nonexistent/toolbox' not found
FAQ
- Does
rmpathinsist on absolute paths? No. Relative inputs are resolved against the current working directory and stored as absolute paths before matching against the path. - What happens with duplicate folders in the argument list? Each folder is processed once per call. Duplicate input values are ignored after the first removal.
- How do I confirm removal succeeded? Call
path()orwhichto confirm that the folder (or files within it) no longer appear on the MATLAB search path. - Does
rmpathupdate theRUNMAT_PATHenvironment variable? Yes. Changes are reflected immediately so other RunMat tooling observes the new path. - Can I remove folders that were added via
path(newPath)? Yes.rmpathmatches entries exactly as they appear in the stored search path string, regardless of how they were inserted. - Will
rmpathaccept GPU strings? Yes. Inputs are gathered automatically, then processed on the CPU. - What happens if the folder exists locally but is not on the search path? RunMat raises
rmpath: folder '<name>' not on search path, matching MATLAB’s expectation that only active path entries are removed. - Does
rmpathreturn the new or previous path? It returns the previous path so you can restore it later withpath(old). - Is there a bulk reset option? To clear the path entirely call
path("").rmpathintentionally targets specific folders.
See Also
path, addpath, genpath, which, exist
Source & Feedback
- Source:
crates/runmat-runtime/src/builtins/io/repl_fs/rmpath.rs - Found an issue? Open a GitHub ticket with a repro.