停止 MATLAB GUI 回调

发布于 2024-10-11 18:23:50 字数 645 浏览 2 评论 0原文

我有一个开始和停止按钮。当我点击开始时,我在回调中运行了一堆代码。它基本上是一个连续的“脚本”,打开阀门,分配水,然后关闭阀门......没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长不大的小祸害 2024-10-18 18:23:50

无论它是否是循环,您都将被迫在代码中插入“检查点”,程序将在其中继续或停止执行。查看函数,命令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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文