\section{EXIST Test for Existence}

\subsection{Usage}

Tests for the existence of a variable, function, directory or
file.  The general syntax for its use is
\begin{verbatim}
  y = exist(item,kind)
\end{verbatim}
where \verb|item| is a string containing the name of the item
to look for, and \verb|kind| is a string indicating the type 
of the search.  The \verb|kind| must be one of 
\begin{itemize}
\item  \verb|'builtin'| checks for built-in functions

\item  \verb|'dir'| checks for directories

\item  \verb|'file'| checks for files

\item  \verb|'var'| checks for variables

\item  \verb|'all'| checks all possibilities (same as leaving out \verb|kind|)

\end{itemize}
You can also leave the \verb|kind| specification out, in which case
the calling syntax is
\begin{verbatim}
  y = exist(item)
\end{verbatim}
The return code is one of the following:
\begin{itemize}
\item  0 - if \verb|item| does not exist

\item  1 - if \verb|item| is a variable in the workspace

\item  2 - if \verb|item| is an M file on the search path, a full pathname
 to a file, or an ordinary file on your search path

\item  5 - if \verb|item| is a built-in FreeMat function

\item  7 - if \verb|item| is a directory

\end{itemize}
Note: previous to version \verb|1.10|, \verb|exist| used a different notion
of existence for variables: a variable was said to exist if it 
was defined and non-empty.  This test is now performed by \verb|isset|.
\subsection{Example}

Some examples of the \verb|exist| function.  Note that generally \verb|exist|
is used in functions to test for keywords.  For example,
\begin{verbatim}
  function y = testfunc(a, b, c)
  if (~exist('c'))
    % c was not defined, so establish a default
    c = 13;
  end
  y = a + b + c;
\end{verbatim}
An example of \verb|exist| in action.
\begin{verbatim}
--> a = randn(3,5,2)

a = 

(:,:,1) = 

    0.8887   -0.2749   -0.1202    0.2347    0.2815 
   -0.9052    0.2688    1.9047   -0.0533   -1.6196 
   -1.6519    0.1689    0.5134   -0.5795    0.7863 

(:,:,2) = 

    0.8246   -0.5823   -0.6986    0.3591   -2.5987 
   -0.5022    2.4368    1.2679   -1.4748   -0.4239 
   -0.9966   -0.5530   -0.3325    2.2984    0.5024 

--> b = []

b = 
  []
--> who
  Variable Name      Type   Flags             Size
              a    double                    [3 5 2]
              b    double                    [0 0]
--> exist('a')

ans = 

 1 

--> exist('b')

ans = 

 1 

--> exist('c')

ans = 

 0 


\end{verbatim}
