MATLAB: How to Change the Min property of slider

minslider

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 );

Best Answer

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);