MATLAB Answers

Calling dbquit('all') from the UI thread

12 views (last 30 days)
MaxK on 27 Apr 2016
Commented: Adam Danz on 2 Dec 2020
I have a question regarding a dbquit call from the UI thread. We are doing the following: We launch a gui where some parameters can be entered and then the calculation can be started by pressing a start button. Further there is an abort button which when pressed stops the calculation. Now the problem is when we debug our calculation. Let's say we have hit a break point in the calculation. In the abort callback function we call: dbquit('all');
The versions R2014a and before worked as expected, i.e. it quitted the debug mode. Since R2014b and still in R2016b Matlab prints the following error message:
Error using dbquit Debug commands only allowed when stopped in debug mode.
Error in gui>button_abort_call (line 389) dbquit('all');
Error while evaluating UIControl Callback
And the debug session is still running. Is there a possibility to stop all debug sessions from the UI thread in Matlab R2016a?
Thank you very much.

  1 Comment

KAE on 13 Jun 2017
Matlab should have a video tutorial on debugging GUIs with this and other tips such as these. If you are new to GUIs you are debugging a lot, yet you don't know how to do it. Also note Yair Altman's description of a debugging bug in in GUIs here (search for 1-MH5KVI).

Sign in to comment.

Answers (3)

Brian Emery
Brian Emery on 25 Aug 2016
I had the same problem. It appears that R2016 does not allow the use of dbquit from within a function or script. This behavior breaks my shortcut function for clearing all variables, closing files and quitting the debugger.
The workaround is to simulate keyboard input of the dbquit shortcut 'shift+f5' using the java robot class. A bit ridiculous (!) but here it is (using code found on matlabcentral):
% Initialize the java engine
import java.awt.*;
import java.awt.event.*;
%Create a Robot-object to do the key-pressing
%Commands for pressing keys:
% shift + f5 :
% end
Here are links for reference:
Hope someone finds a better solution!


KAE on 16 Jun 2017
Another workaround, since some time has gone by, is to use a later Matlab version. I have this problem in R2015b but not in R2017a.
Adam Danz
Adam Danz on 2 Dec 2020
In r2020b debug commands are only allowed when stopped in debug mode. Calling dbquit within a script or function will result in an error.

Sign in to comment.

MaxK on 23 Sep 2016
Thank you. It's working great.


Sign in to comment.

Nicholas on 18 Aug 2019
Thank you!!!
I'm running Matlab 2017a. For me, it never worked the first time I called it in Matlab. It worked every time after the first time. I worked around that by doing the following:
Firstly, I put the following lines of code in my startup.m file:
import java.awt.Robot;
import java.awt.event.KeyEvent;
rob = Robot; %Create a Robot-object to do the key-pressing
rob.keyPress( KeyEvent.VK_SHIFT );
rob.keyRelease( KeyEvent.VK_SHIFT );
This just presses and depresses shift.
After that, I created the following function
function restart
import java.awt.Robot;
import java.awt.event.KeyEvent;
rob = Robot; %Create a Robot-object to do the key-pressing
rob.keyPress( KeyEvent.VK_SHIFT );
rob.keyPress( KeyEvent.VK_F5 );
rob.keyRelease( KeyEvent.VK_SHIFT );
rob.keyRelease( KeyEvent.VK_F5 );
Then, startup runs the code to press and depress shift. After that the restart function works every time.


Sign in to comment.


Community Treasure Hunt

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

Start Hunting!