Getting GUI Slider updates while dragging

조회 수: 21 (최근 30일)
Norton Allen
Norton Allen 2012년 10월 23일
답변: AG 2019년 2월 20일
Is there a straightforward method to get updates on a slider's position while it is being dragged? The standard callback gets called only after the drag is complete and the button has been released.
I'm thinking of using the ButtonDownFcn to start a polling loop checking the slider's value. (Then how do I detect mouse up?)
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2012년 10월 23일
ButtonDownFcn is disabled over an enabled uicontrol
Norton Allen
Norton Allen 2012년 10월 24일
편집: Norton Allen 2012년 10월 24일
Matt, what I'm trying to do is get a slider where the app updates while the slider is moving, for example the way a browser updates while you are moving the scroll bar.
Sean, I did discover that ButtonDownFcn is not the answer pretty quickly too!

댓글을 달려면 로그인하십시오.

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 10월 23일
This can be done easily with addlistener
h = uicontrol('style','slider','callback',@(src,evt)disp(get(src,'value')));
addlistener(h,'Value','PreSet',@(~,~)disp('hi'));
  댓글 수: 3
Mohamad Roslan Mohd Roshdi
Mohamad Roslan Mohd Roshdi 2016년 1월 24일
Hi How to get the slider update value into variable?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

AG
AG 2019년 2월 20일
The following worked for me. I get a 'live' scroll-bar update by calling this within another function:
slider_value = get(gcf.Children(j), 'Value');
...where j is the value of the UIcontrol corresponding to the scroll. You can find out which UIControl it is in the figure by putting a break in the code and using:
gcf.Children
This could also be ascertained in run-time using:
for j = 1:length(gcf.Children)
get(gcf.Children(j), 'Tag')
end
which will return a char array with the Tag of each of the children which could then be compared using strcmp(), for example. I've done this using a GUI created with GUIDE.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by