How to eval an expression without an error?
2 views (last 30 days)
Guillaume on 16 Oct 2018
Not withstanding that using eval is a really bad idea, if you do really want to do it and not stop on error, wrap it in a try statement.
I'd recommend you catch the error, to check that it is indeed due to a missing variable and not some syntax error in your eval:
if ~strcmp(mexc.identifier, 'MATLAB:UndefinedFunction') %the exception you get for undefined function or variable
rethrow(mexc); %not the error we expected, really error as something else happened