Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top