Hello,
Is there a way to avoid/throw a warning/throw an error when a variable is created inside an if-statement?
For example:
if some_condition % This variable did not exist before the if-statement
something = rand(5);endresult = SOMEFUNCTION(something);
If the condition some_condition is not fulfilled, the program will crash. This is a really bad practice and it is allowed by Matlab without a warning. Unfortunately the code I am maintaining is full with these cases.
In general, it would be better if Matlab throws an error whenever a variable is created inside an if-statement even if the if-elseif-else case covers all the possible outcomes.
Best Answer