As you found out yourself, the Matlab callback is not called when the value is already at the maximum (or minimum).
One way would be to retrieve the java handle of the slider, and act on the event that will be fired when you click the slider button, but this would be half way into the 'undocumented' functionalities and has a chance (albeit small in this case) of not being compatible in future releases.
A pure Matlab way to get round your problem is to use another event available from the slider, the KeyPressedFcn
.
For example, you could decide that action with the mouse would only move the slider values between the set boundaries, but hitting +
or -
on the keyboard could override the maximum/minimum and reset them a bit further away.
This is implemented in this minimal example. Save the code below into a single slidertest.m
file, then run it. Try to navigate to the min/max with the mouse, then with the +
and -
keys and see how it works. You should be able to implement more complex behaviour relatively simply if you need to.
Simple slider with expendable boundaries :

function h = slidertest
h.f = figure('Position',[200 200 500 150],'Menubar','none') ;
h.sld = uicontrol('style','slider','position',[20 20 460 30],...
'Min',0 , 'Max',10 , 'SliderStep',[0.01 0.1] , 'Value', 1 , ...
'Tooltip','Use the `+` and `-` keys to override min and max boundaries') ;
h.txt = uicontrol('style','text','position',[20 80 460 40],'String','1','Fontsize',20) ;
set(h.sld,'Callback', {@sld_callback,h} ) %// set the Callback function for the slider
set(h.sld,'KeyPressFcn', {@sld_KeyPressFcn,h} ) %// set the KeyPress function for the slider
function sld_callback(hobj,~,h)
val = get(hobj,'Value') ;
set( h.txt,'String', num2str(val) )
%// put here whatever code has to be executed when you change the slider value
function sld_KeyPressFcn(hobj,evt,h)
minval = get(hobj,'Min') ;
maxval = get(hobj,'Max') ;
val = get(hobj,'Value') ;
keyIncrement = 1 ; %// define that to what suits you
switch evt.Character
case '+'
%// check if we have to increase the 'Max' before we change the value
if (val+keyIncrement) > maxval
set( hobj , 'Max' , maxval+keyIncrement ) ;
end
%// increment the value
set( hobj , 'Value' , val+keyIncrement ) ;
case '-'
%// check if we have to decrease the 'Min' before we change the value
if (val-keyIncrement) < minval
set( hobj , 'Min' , minval-keyIncrement ) ;
end
%// decrement the value
set( hobj , 'Value' , val-keyIncrement ) ;
otherwise
%// if you think about other cases ...
end
%// this is called just to update the display
%// in your case it would insure whatever callback code you have for the
%// slider is executed with the new value
sld_callback(hobj,[],h)