How can I test for a return in 2010a

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
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?
I coded the other function, it has to stop because otherwise it starts looking outside an vector, hence creating an error and stopping the whole thing

Sign in to comment.

 Accepted 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
...

1 Comment

Right! how did I not think of that?
Thanks a lot!

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 27 Mar 2014

Commented:

on 28 Mar 2014

Community Treasure Hunt

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

Start Hunting!