Slider component, unity steps
이전 댓글 표시
I have a sldier component that I want to increment in unity steps. The minimum needs to be 1 and the max is a variable but will be between 10 and 30.
I can't understand the set properties of the slider component, it appears min and max work but min must be 0, it can't be 1. But then the step size seems to be in fractions??
채택된 답변
추가 답변 (1개)
It is easy to define the slider steps to be unity (or any other value): you just need to divide the desired step size by the range of the slider. Here is some demonstration code:
val_min = -3;
val_max = 14;
stepSz = [1,5]; % <- [minorStep,majorStep]
uicontrol('Style','slider', 'Units','normalized',...
'Position',[0.1,0.1,0.8,0.1], 'Min',val_min, 'Max',val_max',...
'SliderStep',stepSz/(val_max-val_min),...
'Callback',@(h,~)disp(get(h,'Value')));
Note how the slider step is simply defined as stepSz/(val_max-val_min), i.e. the desired step size divided by the range. Note the step size has two values: [minorStep,majorStep], the documentation explains these as:
- The slider Value property increases or decreases by the value of minorstep when the user presses an arrow key.
- The slider Value property increases or decreases by the value of majorstep when the user clicks the slider trough.
Note that sliding the bar with the mouse will still result in non-integer values, and some floating-point-precision-rounding may result in non-integer values too. This can be resolved by simply rounding the Value whenever it is used, outside of the slider environment.
카테고리
도움말 센터 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!