6

I am debugging a program in MATLAB R2016a and would like to return from a sub-function without completing the function. For example, you can write in code:

if(conditionMet)
  return;
end

If the condition is met, it will force the function to end early and continue in the caller code. While I am debugging, I would like to force the function to end early as if I had encountered a return command. When I simply type return while in debug mode, nothing appears to happens. Is there a way to force a function to end early and continue running?

1
  • 1
    I think you want to write command 'return' in command window to leave the method in middle of execution and do not think it is possible. I think solution provided by @m7913d is the only option. Commented Mar 10, 2017 at 21:44

2 Answers 2

4

According to MATLAB Central and Undocumented Matlab, there is an undocumented function feature() that could be used in your case like this:

if feature('IsDebugMode')
   return;
end
Sign up to request clarification or add additional context in comments.

Comments

2

I think it is not possible in general with the current release of Matlab.

If you know at beforehand at which place(s) you potentially want to return from your function while debugging, you can use the following trick.

function yourFunction ()
    breakDebug = false;
    ...
    if breakDebug
        return; % location at which you may break your function during debugging
    end
    ...
    return;
end

By setting breakDebug while debugging, the program will break at your next potentially break location.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.