检查滑块是否已移动

Check if slider have been moved

如何检查 MATLAB GUI 中的滑块是否已被使用,即用户是否与滑块进行了交互?

滑块由以下 GUI 代码给出:

uicontrol(fig,'Style','Slider','Units','characters','Position',[17.1+f*iwidth 10.5 8 59.6],'Min',0,'Max',1000,'Value',500,'SliderStep', [1/500 , 20/500 ],'Tag',['slider' int2str(f)]);

有什么巧妙的方法吗?

您唯一需要添加的是回调函数。您可以使用相同的 uicontrol 命令添加它。

uicontrol(fig,'Style','Slider','Units','characters','Position',[17.1+f*iwidth 10.5 8 59.6],'Min',0,'Max',1000,'Value',500,'SliderStep', [1/500 , 20/500 ],'Tag',['slider' int2str(f)], 'Callback', @myfunc);

然后你需要编写 myfunc,像这样:

function myfunc(source,event)
value = source.Value % This is the position of the slider
end