Snap slider values to ticks with ValueChangingFcn Callback

6 views (last 30 days)
Hi,
I'm working with the app designer and want to create a slider that snaps to the tick values while I'm dragging it. The tick values are definded from a vector and set within the startupfcn.
App StartUpFcn:
app.Slider.Limits = [min(app.vector),max(app.vector)];
app.Slider.MinorTicks = app.vector; % app.vector only contains unique values
Slider Callback:
[val,idx] = min(abs(app.vector-app.Slider.Value));
app.Slider.Value = app.vector(idx);
It works fine when I'm using the ValueChangedFcn Callback, but doesn't when I try to use the ValueChangingFcn Callback. I don't get any error messages either.
Best regards,
Michaela

Answers (1)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi on 16 Dec 2019
‘ValueChangingFcn’ is executed as the user moves the thumb along the slider in the app. It does not execute if the Value property changes programmatically. Whereas ‘ValueChangedFcn’ is executed when the user moves the thumb to a different position on the slider. So implement one of the above functions depending on the usecase.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!