How do I set the slider step value in Matlab?
28 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Jan
2017-3-21
编辑:Jan
2017-3-21
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!