How to enable "Snap to Tick" for a slider in App Designer?

Hi, I want to know how to make a slider move discretely rather than continuously. As an example, I want the slider to jump from 1 to 2 when I move it. In other words, I need to enable the "Snap to Tick" feature.
Thanks in advance.

3 Comments

slider.png
What is yours 'snap to tick'? Do you have photo to illustrate it?
In the same slider you posted, for example I want the slider handle sits on the tick intervals not between them. for example I want 1, 2, 3 ... rather than 1.48
In the callback make the slider value rounded and then set the slider position to this rounded value.

Sign in to comment.

Answers (1)

Untitled.png
Is it what you expect? If you are using app designer, on your left hand side bottom, there is configuration you may edit. Empty the minor tick, and modify the major tick to 1,2,3,4,5.
Don't forgot to change the limit as well to 0,5

4 Comments

Thanks Kevin, but as you see in the screenshot, I have already set up the configuration. However, when I run the app, the handle can sit everywhere rather than just on the intervals.
2.jpg
I use R2018a version.
1.jpg
The only way i can think about it is to create a callback function, then use the round off method to readjust the value of slider if user move the handle to the place between intervals.
Create a callback function for your slider
value = app.Slider.Value;
app.Slider.Value=round( value / 20 ) * 20;
You may change the value of 20 to 2, if the interval is 2.
@Kevin Chng It does not work.
My slider settings:
I have set up slider functions like this:
function SliderValueChanging(app, event)
app.Slider.Value = round(event.Value);
end
function SliderValueChanged(app, event)
app.Slider.Value = round(app.Slider.Value);
end
But the slider behaves like this:
So the SliderValueChanging has no effect.
Is there a way to fix this?

Sign in to comment.

Categories

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

Asked:

on 21 Feb 2019

Commented:

on 11 Aug 2024

Community Treasure Hunt

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

Start Hunting!