Skip to content

exist

Check whether a name exists in the workspace, on disk, or as a built-in.

tf = exist(name)
tf = exist(name, kind)

Returns an integer code indicating what (if anything) the name name refers to:

  • 0 — does not exist
  • 1 — workspace variable
  • 2 — file (script or data file) on the path
  • 5 — built-in MATLAB function
  • 7 — directory on the path
  • 8 — class

With the optional kind argument ('var', 'file', 'class', 'builtin', 'dir'), restricts the search to that one type.

exist('x') % 1 if x is a workspace variable
exist('plot', 'builtin') % 5
  • who — List names of variables in the workspace.
  • whos — List variables in the workspace with detailed info.
  • isvarname — Test whether a string is a valid variable name.