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?
Going to a previously step is not possible in debugging... only option have a new break-point at that point and re-start debugging...
Pressing ctrl+R is the correct option but if your break point is on a line which is inside the for loop, then you will have to first remove the break point and then press ctrl+R on the line on which you want the control to land. I faced this issue while debugging.
Switch to the Run and Debug view (Ctrl+Shift+D) and select the create a launch. json file link. VS Code will let you select an "debugger" in order to create a default launch configuration.
To debug a function which is defined inside another function, single-step through to the end of its definition, and then call debug on its name. If you want to debug a function not starting at the very beginning, use trace(..., at = *) or setBreakpoint .
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With