exist
Check existence of variable, script, function, folder, or class
Description
exist returns the type of
namename as a number. This list describes the type associated
with each value:
0 —
namedoes not exist or cannot be found for other reasons. For example, ifnameexists in a restricted folder to which MATLAB® does not have access,existreturns 0.1 —
nameis a variable in the workspace.2 —
nameis a file with extension.m,.mlx, or.mlapp, ornameis the name of a file with a non-registered file extension (.mat,.fig,.txt).3 —
nameis a MEX file on your MATLAB search path.4 —
nameis a loaded Simulink® model or a Simulink model or library file on your MATLAB search path.5 —
nameis a built-in MATLAB function. This does not include classes.6 —
nameis a P-code file on your MATLAB search path.7 —
nameis a folder.8 —
nameis a class. (existreturns 0 for Java classes if you start MATLAB with the-nojvmoption.)
MATLAB searches starting at the top of the search path, and moving down until
a result is found or the last folder on the path is reached. If more than one
name exists in a folder, MATLAB displays the first instance of name, according to
the Function Precedence Order. Folders
are an exception to the function precedence rules. They have precedence over all
types except for variables and built-in functions.
For example, if name matches both a file
with a .m extension and a P-code file, then exist returns
6, identifying it as a P-code file. If name matches
both a variable and a P-code file, exists returns 1, identifying it
as a variable. If name matches both a folder and
a MATLAB function, exist returns 7,
identifying it as a folder.
exist returns
the type of name searchTypename, restricting results to the specified
type, searchType. If name of
type searchType does not exist, MATLAB returns 0.
Examples
Input Arguments
Output Arguments
Limitations
MATLAB does not support internet URLs that require authentication.
MATLAB Online™ supports internet URLs associated with Microsoft® OneDrive™ files and folders, while the installed version of MATLAB supports only local OneDrive files.
Alternative Functionality
To check the existence of a file or folder, you also can use the
isfolderorisfilefunctions.existsearches for files and folders on the search path, which can lead to unexpected results.isfolderandisfilesearch for files or folders only on the specified path or in the current folder, which can lead to clearer and faster results.