Snap slider values to ticks with ValueChangingFcn Callback

9 次查看(过去 30 天)
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

回答(1 个)

Sahithi Kanumarlapudi
‘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.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by