Snap slider values to ticks with ValueChangingFcn Callback

조회 수: 9 (최근 30일)
Michaela Zoll
Michaela Zoll 2019년 12월 11일
답변: Sahithi Kanumarlapudi 2019년 12월 16일
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
Sahithi Kanumarlapudi 2019년 12월 16일
‘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