문제

가이드를 사용하여 MATLAB GUI를 만들었습니다.콜백 함수가있는 슬라이더가 있습니다.슬라이더의 움직임에 '슬라이더가 움직이고 마우스가 출시되면 실제로 만 실행되는이 콜백은이 콜백을 알아 차렸다.

플롯의 라이브 업데이트를 위해 슬라이더가 끌리면서 스크립트를 실행할 수있는 방법이 있습니까?스크립트가 너무 많이 실행되는 것을 멈추는 것이 뭔가가 될 필요가있을 필요가 있으므로

도움이 되었습니까?

해결책

Even though the callback of the slider isn't being called as the mouse is moved, the 'Value' property of the slider uicontrol is being updated. Therefore, you could create a listener using addlistener that will execute a given callback when the 'Value' property changes. Here's an example:

hSlider = uicontrol('Style', 'slider', 'Callback', @(s, e) disp('hello'));
hListener = addlistener(hSlider, 'Value', 'PostSet', @(s, e) disp('hi'));

As you move the slider you should see 'hi' being printed to the screen (the listener callback), and when you release the mouse you will see 'hello' printed (the uicontrol callback).

다른 팁

Just for the record, this subject is discussed in detail here: http://UndocumentedMatlab.com/blog/continuous-slider-callback/ - several alternative solutions are presented there. gnovice's solution using addlistener is equivalent to the handle.listener alternative, since addlistener is basically just a wrapper for the latter.

If you want to execute the same original callback you passed to uicontrol you can add this generic listener which bootstraps the existing callback:

sld.addlistener('Value','PostSet',@(src,data) data.AffectedObject.Callback(data.AffectedObject,struct('Source',data.AffectedObject,'EventName','Action')));

Related blog post

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top