No Matlab, como você pode ter um retorno de chamada é executado enquanto um controle deslizante está sendo arrastado?

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

Pergunta

Eu criei um Matlab GUI usando o guia.Eu tenho um controle deslizante com uma função de retorno de chamada.Eu notei que esse retorno de chamada, que deve executar 'no movimento do controle deslizante', de fato funciona apenas quando o controle deslizante foi movido e o mouse lançado.

Existe uma maneira de obter um script para ser executado enquanto o controle deslizante está sendo arrastado, para atualização ao vivo de um enredo?Eu pretenderia a necessidade de ser algo para parar o script sendo executado muitas vezes.

Foi útil?

Solução

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

Outras dicas

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top