Snap slider values to ticks with ValueChangingFcn Callback

10 visualizaciones (últimos 30 días)
Michaela Zoll
Michaela Zoll el 11 de Dic. de 2019
Respondida: Sahithi Kanumarlapudi el 16 de Dic. de 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

Respuestas (1)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi el 16 de Dic. de 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.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by