How to Change the Min property of slider?

조회 수: 3 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2017년 2월 21일
댓글: Adam 2017년 2월 21일
The code below works perfectly until I change Min from 0 to 1. Why cannot I set it 1? What is the solution?
function test3()
hfig = figure();
slider = uicontrol('Parent', hfig,...
'Style', 'Slider',...
'Tag', 'slider1',...
'Callback', @slider_callback,...
'Min', 0,...
'Max', 40,...
'SliderStep', [1/40 10/40]);
function slider_callback(hObject, eventdata)
a = get(hObject, 'Value');
disp( a );
  댓글 수: 1
Jan
Jan 2017년 2월 21일
Please use the "{} Code" button to format code in the forum. I've done this for you this time.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 2월 21일
편집: Jan 2017년 2월 21일
When you set the 'Min' value to 1, the current 'Value' is still at 0. Therefore you should see the warning:
Warning: slider control can not have a Value outside of Min/Max range
Control will not be rendered until all of its parameter values are valid
Considering this:
function test4()
hfig = figure();
slider = uicontrol('Parent', hfig,...
'Style', 'Slider',...
'Tag', 'slider1',...
'Callback', @slider_callback,...
'Min', 1, 'Max', 40,...
'Value', 1, ... % <- Inside [Min, Max]
'SliderStep', [1/40 10/40]); % Perhaps [1/39, 10/39]
function slider_callback(hObject, eventdata)
a = get(hObject, 'Value');
disp(a);
  댓글 수: 3
Jan
Jan 2017년 2월 21일
The OpeningFcn is fine.
Adam
Adam 2017년 2월 21일
I usually factor it out into another function that I call from the _OpeningFcn, just to keep it a bit tidier, but it all amounts to the same thing.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by