How do I set the slider step value in Matlab?

26 Ansichten (letzte 30 Tage)
Nur Shaheera
Nur Shaheera am 21 Mär. 2017
Bearbeitet: Jan am 21 Mär. 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

Akzeptierte Antwort

Jan
Jan am 21 Mär. 2017
Bearbeitet: Jan am 21 Mär. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Data Exploration finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by