exist — Return the documented numeric code for a variable, file, folder, builtin, model, or class.
exist searches the active workspace and configured search path and returns a host double scalar code from 0 through 8. The optional documented searchType values are builtin, class, dir, file, and var.
Syntax
exist name
exist name searchType
typeID = exist(name)
typeID = exist(name, searchType)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | StringScalar | Yes | — | Variable/function/file/class name to query. |
type | StringScalar | Yes | — | Documented query kind: builtin|class|dir|file|var. |
Returns
| Name | Type | Description |
|---|---|---|
typeID | NumericScalar | Existence code (0,1,2,3,4,5,6,7,8) following MATLAB semantics. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:exist:TooManyInputs | More than two total input arguments are provided. | exist: too many input arguments |
RunMat:exist:InvalidName | Name input is not a character vector or string scalar/array scalar. | exist: name must be a character vector or string scalar |
RunMat:exist:InvalidTypeArgument | Type input is not a character vector or string scalar/array scalar. | exist: type must be a character vector or string scalar |
RunMat:exist:InvalidType | Type input is not one of the supported exist query types. | exist: invalid type. Type must be one of 'builtin', 'class', 'dir', 'file', or 'var' |
How exist works
- The documented return codes are 0 not found or inaccessible, 1 variable, 2 general file, 3 MEX file, 4 loaded or on-path Simulink model, 5 builtin, 6 P-code, 7 folder, and 8 class.
- Without searchType, variables and builtins have highest precedence; folders then precede classes and files; remaining file kinds follow function precedence within search-path order.
exist(name,'file')searches files and folders and can therefore return 2, 3, 4, 6, 7, or 0.nameand documented searchType values are host string scalars or character vectors. Integer and logical inputs are inapplicable and reject without conversion.- RunMat supports additional selector aliases and specialized selectors for its own runtime. They are an explicit RunMat-only extension and reject in MATLAB compatibility mode.
exist(handleObject,'handle')with a nontext first argument is a separate RunMat-only extension.- Arbitrary unauthenticated HTTP and HTTPS URL lookup, JVM class discovery, and loaded Simulink runtime state remain environment-level gaps. Local and configured RunMat search-path lookup is supported.
GPU memory and residency
No resident path. exist validates host text and performs workspace/filesystem lookup on the CPU.
Examples
Check a workspace variable
alpha = 1;
typeID = exist('alpha','var')Expected output:
typeID = 1Check a folder through the file filter
mkdir('logs');
typeID = exist('logs','file')Expected output:
typeID = 7Check a builtin
typeID = exist('sin','builtin')Expected output:
typeID = 5Using exist with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how exist changes the result.
Run a small exist example, explain the result, then change one input and compare the output.
FAQ
What data type is typeID?⌄
It is a host double scalar whose value is an integer code. It is not typed-integer storage.
Do wildcard names work?⌄
No. Names containing wildcard characters do not perform a wildcard search and return 0.
Does RunMat support every MATLAB environment-backed code?⌄
Filesystem MEX, P-code, Simulink-extension, builtin, folder, file, and RunMat class discovery are represented. JVM discovery, loaded Simulink state, and arbitrary web URL lookup need broader environment infrastructure.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite
Tabular
arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines
Import
Json
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how exist is executed, line by line, in Rust.
- View the source for exist 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.