Listener not responding to ui slider

조회 수: 7 (최근 30일)
Sebastian
Sebastian 2025년 3월 20일
답변: Image Analyst 2025년 3월 21일
I didn't like how the normal callback implementation on the slider only updated once I stop dragging it, so I tried addlistener instead, but for some reason it just doesn't respond at all. As a simple example, for the following code
sld = uicontrol('Style','slider');
lst = addlistener(sld,'Value','PostSet',@(src,evt)disp('value changed'));
Changing the value of the slider directly from the Command Window ( sld.Value=0.5; ) causes the callback function to run, but moving the slider or pressing the arrows on its ends does nothing.
What am I doing wrong?
  댓글 수: 4
Sebastian
Sebastian 2025년 3월 20일
@Les Beckham, I'm on R2024b. I'm also running on LinuxMint if that helps at all - I've had a couple specific and weird issues in the past that I'm pretty sure were Linux-specific.
Les Beckham
Les Beckham 2025년 3월 20일
Ah yes, that could be a difference as well. I'm on Windows 10. I'll report the issue with 2025a. Sorry to not have any more ideas to help you.

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

답변 (1개)

Image Analyst
Image Analyst 2025년 3월 21일
If you use AppDesigner then you can use the "Value changing" event to do an instantaneous/live updating of the displayed value. For example, here is an example from one of my programs:
% Value changing function: sldOpacity
function sldOpacityValueChanging(app, event)
changingValue = event.Value;
tt = sprintf('%.1f %% original and %.1f %% colorized', changingValue, 100-changingValue);
app.lblOpacity.Text = tt; % Change static text label above the slider.
app.lblOpacity.Tooltip = tt;
end

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by