停止 MATLAB GUI 回调
我有一个开始和停止按钮。当我点击开始时,我在回调中运行了一堆代码。它基本上是一个连续的“脚本”,打开阀门,分配水,然后关闭阀门......没有 while() 循环,并且不会重复。我希望能够随时使用“停止”按钮停止此过程。我见过的大多数相关答案都是在使用 while() 循环的情况下。有些人还建议定期检查是否按下了“停止”按钮(使用变量或句柄变量)。
由于我没有 while 循环,因此无法以这种方式解决它。另外,我希望能够立即退出,而不必定期检查(因为在我的代码中多次检查会很丑陋且令人困惑)。有没有办法终止被 STOP 按钮中断的回调?如果没有,是否可以让“开始”按钮运行 .m 文件,然后让“停止”按钮终止该 .m 文件?
最坏的情况是定期检查变量。
更新: 嗯,看起来最坏的情况是 MATLAB 所建议的...... http:// /www.mathworks.com/support/solutions/en/data/1-33IK85/index.html?product=ML&solution=1-33IK85
谢谢。
I have a START and STOP button. When I hit START, i run a bunch of code in my callback. It's basically a sequential "script" that opens valves, dispenses water and then closes the valves...there is no while() loop and it doesn't repeat. I want to be able to stop this process at any time using the STOP button. Most of the related answers I've seen are in the cases where a while() loop is used. Some people have also suggested to periodically check if the STOP button was pressed (using a variable or handle variable).
Since I do not have a while loop, I can't solve it that way. Also, I'd like to be able to exit immediately, without having to periodically check (because checking multiple times in my code would be ugly and confusing). Is there a way to terminate the callback which was interrupted by the STOP button? If not, is it possible to have the START button run a .m file and then have the STOP button terminate that .m file?
The worst case scenario would be to check a variable periodically.
UPDATE:
Well, looks like the worst case scenario is what is suggested by MATLAB...
http://www.mathworks.com/support/solutions/en/data/1-33IK85/index.html?product=ML&solution=1-33IK85
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论它是否是循环,您都将被迫在代码中插入“检查点”,程序将在其中继续或停止执行。查看函数,命令
return
将在所需的点恢复执行。您可以选择的只是使用 事件“停止触发器”传播的“方法”和 Listeners 或 The MathWorks 提供的解决方案。
Whether it is a loop or not, you will be forced to insert 'checkpoints' in your code where program execution shall continue or stop. Looking at functions, the command
return
will resume execution at a desired point.All you can choose is the 'method' of 'Stop Trigger' propagation using Events and Listeners or the solution provided by The MathWorks.