How to stop a running script with a push-button and return best solution so far to GUI surface?

1 次查看(过去 30 天)
Hi people,
i implemented a GUI with GUIDE that executes an algorithm by pushing a PUSH-Button. The algorithm tends to produce better solutions the longer it runs. The call of the algorithm looks like
[solution_value]=heuristic.m
Now i would like the user to have the possibility to stop the running algorithm and to return the best solution value "solution_value" that was calculated so far! so i dont want to wait until the algorithm is fully finished but stop the execution and return the current value of the return variable... The whole algorithm runs in a while loop, so it would be enough to make the algorithm jump out of the while loop...After that the return variable is assigned in the algorithm and can be given back to the GUI as usual..
How can i manage that?
Thank you very much and best regards, John
  1 个评论
John
John 2016-1-2
When posting the question a simple solution came into my mind:
so i just defined a global variable "stop" that is called into existence as soon as the push button for stopping the function is pressed...
a simple
if stop==1
break
end
manages to break out of the while loop and thats it! Sometimes even just formulating a question really helps:D
best regards

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by