MATLAB: How to test for a return in 2010a

breakreturn

Hello everyone,
I have a program that calls a function. I would like to put a test in this function that would call "return" is true. however, that function is called in a loop so I would like to test if the function was ended prematurely and call "break" on the loop.
something along the lines of that:
if return==true
break
else
Is there anyway to actually do that?

Best Answer

Sure...just add another return variable flag and test it...
function [other return vars flag]=yourfunction(inputs)
...
flag=false;
...
% oops, an error or something happened
if bomb_condition
flag=true;
return
end
...
Use like
...
[var1, flg]=yourfunction(x);
if flg, break, end
...