MATLAB Function Reference
  Go to function:
    Search    Help Desk 
exist    Examples   See Also

Check if a variable or file exists

Syntax

Description

a = exist('item') returns the status of the variable or file item:

0
If item does not exist.
1
If the variable item exists in the workspace.
2
If item is an M-file or a file of unknown type.
3
If item is a MEX-file.
4
If item is a MDL-file.
5
If item is a built-in MATLAB function.
6
If item is a P-file.
7
If item is a directory.

exist('item') returns 2 if item is on the MATLAB search path. item may be a MATLABPATH relative partial pathname. item may be item.ext, but the filename extension (ext) cannot be mdl, p, or mex.

ident = exist('item','kind') returns logical true (1) if an item of the specified kind is found, and returns 0 otherwise. kind may be:

var
Checks only for variables.
builtin
Checks only for built-in functions.
file
Checks only for files.
dir
Checks only for directories.

Examples

exist can check whether a MATLAB function is built-in or a file:

plot is a built-in function.

See Also

dir, help, lookfor, partialpath, what, which, who



[ Previous | Help Desk | Next ]