如何使用 scilab 中的按钮停止操作
How to stop an action with a button in scilab
我希望能够通过按下另一个按钮来停止由一个按钮启动的功能。更准确地说,我想通过更改参数来停止 while 循环:
stop=%F
while ... & stop<>%T
...
end
我尝试编写一个回调函数来更改变量以停止 while :
function callback(handles)
stop=%T
end
但是在上一个动作结束之前没有触发动作。
我想一定有一些线程与某些线程有关,但我在 scilab 中没有这方面的知识。
你有两个解决方案。第一个有优先表达式回调:
b = uicontrol("style","pushbutton","callback","stop=%t","callback_type",10);
stop = %f;
while ~stop
sleep(1)
end
第二个优先回调函数:
function fun()
stop = %t;
stop = resume(stop);
end
b = uicontrol("style","pushbutton","callback","fun","callback_type",12);
stop = %f;
while ~stop
sleep(1)
end
在第二种情况下,您必须使用 resume
到 return 主工作区中的局部变量 stop
。使回调优先是中断等待循环的必要条件。
我希望能够通过按下另一个按钮来停止由一个按钮启动的功能。更准确地说,我想通过更改参数来停止 while 循环:
stop=%F
while ... & stop<>%T
...
end
我尝试编写一个回调函数来更改变量以停止 while :
function callback(handles)
stop=%T
end
但是在上一个动作结束之前没有触发动作。
我想一定有一些线程与某些线程有关,但我在 scilab 中没有这方面的知识。
你有两个解决方案。第一个有优先表达式回调:
b = uicontrol("style","pushbutton","callback","stop=%t","callback_type",10);
stop = %f;
while ~stop
sleep(1)
end
第二个优先回调函数:
function fun()
stop = %t;
stop = resume(stop);
end
b = uicontrol("style","pushbutton","callback","fun","callback_type",12);
stop = %f;
while ~stop
sleep(1)
end
在第二种情况下,您必须使用 resume
到 return 主工作区中的局部变量 stop
。使回调优先是中断等待循环的必要条件。