Clear Filters
Clear Filters

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

2 views (last 30 days)
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 Comment
John
John on 2 Jan 2016
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

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!