I have created a MATLAB GUI using GUIDE. I have a slider with a callback function. I have noticed that this callback, which is supposed to execute 'on slider movement', in fact only runs once the slider has been moved and the mouse released.
Is there a way to get a script to run as the slider is being dragged, for live updating of a plot? There would I presume need to be something to stop the script being run too many times.
Sliders accept numeric input within a specific range by enabling the user to move a sliding bar. Users move the bar by pressing the mouse button and dragging the slide, by clicking in the trough, or by clicking an arrow. The location of the bar indicates a numeric value. Slider Orientation.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With