How to terminate a script using a pushbutton i GUI?

4 views (last 30 days)
JoE
JoE on 28 Apr 2014
Commented: JoE on 30 Apr 2014
Hi all,
I have a GUI with a few buttons that makes some analysis for me. The duration of this analysis can be in range of few seconds to few minutes.
How can I terminate this analysis (manually finish the script behind this analysis) using one of those buttons (e.g. with the caption 'STOP')?
Is there a way how to do this in GUI (command, keyword or anything else)?
Thank you very much for your response.
JoE

Answers (1)

Kyle C
Kyle C on 28 Apr 2014
I'm guessing that if the scripts are taking that long you have some loops in there. One way to stop the scripts is to have the stop button set appdata that signals to the scripts that they should stop running. The loops in the scripts should check to see if this signal is telling it to stop or not before each iteration.
sample:
stopbutton callback
setappdata(0,'stopreq',1)
end
functiontostop callback
if ~getappdata(0,'stopreq')
code here
else
setappdata(0,'stopreq',0)
break
end
for this to work the functiontostop must be interruptable.
  1 Comment
JoE
JoE on 30 Apr 2014
Thanks for the response. I tried this but it did not work. What did you mean the function "functiontostop" must be interruptable?

Sign in to comment.

Categories

Find more on App Building 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!