MATLAB Answers

Resuming from "keyboard" command?

7 views (last 30 days)
Giuseppe Antonio
Giuseppe Antonio on 19 Nov 2019
Answered: Jan on 22 Nov 2019
I'm using the "keyboard" command to stop the execution in a nested (callback) function (which is triggered by a pushbutton) in order to make the user able to modify its workspace.
function myFunc()
...
function myNestedFunc(h,~)
load('myMatFile.mat','myGraph');
openvar myGraph.Edges;
keyboard;
end
end
The problem is, that to exit from the debug mode, the user should run "dbcont" in the Command Window. But I want to resume as soon as he finished to edit the variable.
If I try to write another callback function like this:
function myFunc()
...
function resume(h,~)
dbcont;
end
end
I get the error "Debug commands only allowed when stopped in debug mode".
Is there a way to resume from "keyboard" without forcing the user to manually enter "dbcont" in the Command Window?

  2 Comments

Daniel M
Daniel M on 19 Nov 2019
You can use the eval function along with timer objects to both check the value of a variable, as well as invoke dbcont. I'm on mobile right now, so can't provide a more thorough example/explanation, but hopefully this will get you started.
Giuseppe Antonio
Giuseppe Antonio on 22 Nov 2019
If I use the eval function, I get the error "Debug commands only allowed when stopped in debug mode". I don't know if this depends on the MATLAB versions, but I must use it.
Any suggestions on how to overcome this problem?

Sign in to comment.

Answers (1)

Jan
Jan on 22 Nov 2019
Using debug commands for an interaction with the user is a really bad design. A dynamic modification of the workspace is very fragile.
Resuming the debug mode througth another callback is strange also. Actually you should be able to check, if Matlab is in debug mode currently, but starting another callback while stopped in debug mode in another one, is at least confusing. Even including the dbcont in a try/catch block is not a smart solution - but worth to try for reasons of experiences.
Create a clean GUI for user interactions. Use the debugging methods only for debugging.

  0 Comments

Sign in to comment.