Resuming from "keyboard" command?

68 次查看(过去 30 天)
Giuseppe Antonio
Giuseppe Antonio 2019-11-19
编辑: Jan 2023-2-28
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?
  3 个评论
Giuseppe Antonio
Giuseppe Antonio 2019-11-22
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?
Jan
Jan 2022-11-2
@Giuseppe Antonio: Please open a new thread for a new question. Show the relevant part of the code and a copy of the complete error message.
Combining eval with debugging sounds like a wierd program design. I'm not surprised that such programming constructs are fragile. Do not use such crutches for productive code.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2019-11-22
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.
  5 个评论
Steven Lord
Steven Lord 2023-2-27
I think you've opened a separate question for your specific use case, correct? In that case let's continue the discussion of that use case in that question rather than here, to avoid potential duplication of information and effort.
Jan
Jan 2023-2-27
编辑:Jan 2023-2-28
@Robert Scott: "There is no alternative method suggested." - Surely I've suggested to create a clean, stable and user-friendly GUI. I do not suggest methods, with which the programmer drills a hole in his own knee, and in the knees of the users of the code. If you really want this, post your own solution. You cannot claim, that I write, what you want to hear.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by