exist

Returns an integer (R) based on whether a variable, function, directory, or file with the name s exists in the current session.

Syntax

R = exist(s)

R = exist(s, category)

Inputs

s
Type: string
opt (optional)
Input specifying the category which will be searched for the existence of s. Valid values are:
'var'
Searches for variables.
'builtin'
Searches only for functions.
'dir'
Searches for directories on disk.
'file'
Searches for files on disk.
'class' is for compatibility purposes and is not used to specify any category. If no category is given, the first match for the name in the order of variable, function, dir, or file is returned.
Type: string

Outputs

R
The value of R is one of the following:
0
s does not exist
2
s is a file
5
s is a built-in function
7
s is a directory
103
s is a function.
Type: integer

Examples

Search in all variables, functions, directories, and files:
function myfunc()
    disp('In myfunc')
end
R = exist('myfunc')
R = 103