How can I test for a return in 2010a
1 view (last 30 days)
Show older comments
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?
2 Comments
Marta Salas
on 28 Mar 2014
Edited: Marta Salas
on 28 Mar 2014
The function you call is a MATLAB function? is it a function you code? if the function end prematurely, is it due an error?
Accepted Answer
dpb
on 28 Mar 2014
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
...
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!