MATLAB: Does the EXIST function return an incorrect value in stand-alone mode

compilecompiledcompilerexistMATLABMATLAB Compiler

Why does the EXIST function return an incorrect value in stand-alone mode?
Whenever I try to use the EXIST function in standalone mode, the wrong results are returned.
For instance the following code returns 0 in stand-alone mode:
function redbatmod
eat = 1;
exist('eat')
exist('flames')

Best Answer

The EXIST function has limitations for support in stand-alone mode. For more information, see the solution attached at the bottom of this page.
As a workaround, you can use either NARGIN or the following code, if you wish to check for the existence of a variable:
function texist2
nw = 2;
try
isempty(nw);
myexist=1;
catch
myexist=0;
end
fprintf(1,'exist: %d\n',myexist);