How do I set the slider step value in Matlab?

28 vues (au cours des 30 derniers jours)
Nur Shaheera
Nur Shaheera le 21 Mar 2017
Modifié(e) : Jan le 21 Mar 2017
I want my GUI slider step to start from 1 to 80. Need it to set from 1 to 80 with increment of 1 for every step. I have set the min and max in the property inspector. and the slider step to [1/79 0.1] but its increasing with decimal places.
Example of output = 0,1.04,2.08,...
I am using R2014b

Réponse acceptée

Jan
Jan le 21 Mar 2017
Modifié(e) : Jan le 21 Mar 2017
It is not clear to me, when the value "is increasing in decimal places".
uicontrol('Style', 'Slider', ...
'SliderStep', [1/79, 0.1], ...
'Min', 1, 'Max', 80, 'Value', 1, ...
'Callback', 'disp(get(gcbo, ''Value''))')
Now hitting the arrows increase the value by 1. But hitting in the area increases the value by 7.9 as expected. To get integer results, you can adjust the value in the callback:
uicontrol('Style', 'Slider', ...
'SliderStep', [1/79, 0.1], ...
'Min', 1, 'Max', 80, 'Value', 1, ...
'Callback', @sliderCallback)
function sliderCallback(hObject, EventData)
Value = round(get(hObject, 'Value'));
set(hObject, 'Value', Value);
Now the value is rounded after each interaction.

Plus de réponses (0)

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by