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') or exist('item.ext')returns 2 if item is on the MATLAB search path but the filename extension (ext) is not mdl, p, or mex. item may be a MATLABPATH relative partial pathname.

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         Directory listing

help        Online help for MATLAB functions and M-files

lookfor     Keyword search through all help entries

what        Directory listing of M-files, MAT-files, and MEX-files

which       Locate functions and files

who         List directory of variables in memory

See also partialpath.



[ Previous | Help Desk | Next ]