En Matlab, ¿cómo puede tener un ejecución de devolución de llamada mientras se arrastra un control deslizante?

StackOverflow https://stackoverflow.com/questions/6032924

Pregunta

He creado una Gui Matlab usando.Tengo un deslizador con una función de devolución de llamada.Me he dado cuenta de que esta devolución de llamada, que se supone que debe ejecutar 'en movimiento deslizante', de hecho solo se ejecuta una vez que se ha movido el control deslizante y se lanzó el ratón.

¿Hay alguna manera de obtener un script para ejecutarse a medida que se arrastra el control deslizante, para la actualización en vivo de una parcela?Sería que supongo que debía ser algo para evitar que el script se ejecute demasiadas veces.

¿Fue útil?

Solución

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).

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top