Snap slider values to ticks with ValueChangingFcn Callback

9 vues (au cours des 30 derniers jours)
Michaela Zoll
Michaela Zoll le 11 Déc 2019
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

Réponses (1)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi le 16 Déc 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.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by