Why does the EXIST function return an incorrect value in stand-alone mode?

4 views (last 30 days)
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')

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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);

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!