How to terminate a script using a pushbutton i GUI?

8 次查看(过去 30 天)
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

回答(1 个)

Kyle C
Kyle C 2014-4-28
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 个评论
JoE
JoE 2014-4-30
Thanks for the response. I tried this but it did not work. What did you mean the function "functiontostop" must be interruptable?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by