View all functions

CategoryIo: Repl Fs

What does the addpath function do in MATLAB / RunMat?

addpath prepends or appends folders to the MATLAB search path that RunMat consults when resolving functions, scripts, classes, and data files. The change affects the current session immediately, and the resulting ordering matches MATLAB semantics.

How does the addpath 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 in a single argument using the platform path separator (: on Linux/macOS, ; on Windows); this is compatible with genpath.
  • By default, folders are added to the top of the search path. Use '-end' to append or '-begin' to force prepending explicitly. Only one position flag is permitted.
  • The '-frozen' flag is accepted for MATLAB compatibility. RunMat does not currently track frozen entries separately; the flag simply suppresses incompatibility warnings.
  • Duplicate entries are removed automatically so each folder appears at most once. On Windows, comparisons are case-insensitive.
  • Inputs are resolved to absolute, canonicalised paths. Relative inputs are interpreted relative to the current working directory, and ~ expands to the user’s home directory.
  • Folders must exist. RunMat raises addpath: folder '<name>' not found when a directory is missing or addpath: '<name>' is not a folder when the target is not a directory.

addpath Function GPU Execution Behaviour

addpath 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. addpath operates entirely on CPU-side strings. Supplying gpuArray text inputs offers no benefit—RunMat gathers them automatically.

Examples of using the addpath function in MATLAB / RunMat

Add a single folder to the top of the search path

old = addpath("util/toolbox");
path()

Expected behaviour:

old          % Previous search path as a character vector
% The folder util/toolbox now appears before the old entries.

Append folders to the end of the search path

dirs = ["shared/filters", "shared/signal"];
addpath(dirs, "-end");

Expected behaviour:

% The specified folders are appended to the end of the search path.

Use genpath output to add a folder tree

toolchain = genpath("third_party/toolchain");
addpath(toolchain);

Expected behaviour:

% Every directory produced by genpath is inserted at the top of the search path.

Add folders from a cell array

folders = {'src/algorithms', 'src/visualization'};
addpath(folders{:}, "-begin");

Expected output:

% Both folders appear at the beginning of the MATLAB search path.

Move an existing folder to the top of the search path

addpath("src/algorithms");

Expected behaviour:

% The folder is removed from its previous position and reinserted at the front.

Accept the MATLAB -frozen flag

addpath("vendor/hardware", "-frozen");

Expected behaviour:

% The folder is added; RunMat currently treats '-frozen' as an informational hint.

Retrieve the previous path and restore it later

old = addpath("analysis/utilities");
% ... run experiments ...
path(old);

Expected behaviour:

% The original search path is restored when you call path(old).

Combine multiple options

addpath("contrib", "docs/examples", "-end", "-frozen");

Expected behaviour:

% Both folders are appended to the end of the search path.

FAQ

  • Does addpath insist on absolute paths? No. Relative inputs are resolved against the current working directory and stored as absolute paths.
  • What happens with duplicate folders? Existing occurrences are removed before the new ordering is applied, so each folder appears only once.
  • How do I append instead of prepend? Supply '-end' as the final argument. Use '-begin' to force prepending explicitly.
  • Is -frozen supported? The flag is accepted for MATLAB compatibility. RunMat currently treats it as a no-op but plans to integrate tighter tooling once savepath support lands.
  • Can I load pathdef.m directly? Not yet. RunMat will add parity support in a future release. For now, evaluate the file manually and pass the resulting character vector to path.
  • Do folders need to exist? Yes. RunMat validates that every entry exists and is a directory before updating the search path.
  • Will addpath accept GPU strings? Yes. Inputs are gathered automatically, then processed on the CPU.
  • Does addpath return the new path? Like MATLAB, addpath returns the previous path so it can be restored later with path(old).

See Also

path, rmpath, genpath, which, exist

Source & Feedback