MATLAB Answers


How can i change slider's maximum value according to another slider?

Asked by Mustafa Uysal on 10 Apr 2019
Latest activity Commented on by Geoff Hayes
on 11 Apr 2019
i would like to change slider's maximum value (slider2) according to another slider's value (slider1). My formula is simple. But i don't know how to change slider value. Here is my slider codes:
Slider 1
taper = get(hObject,'value') ;
set(handles.texttaper,'string',num2str(taper)) ;
Slider 2 (i would like to change maximum value of this)
function sliderrs_Callback(hObject, eventdata, handles)
rs = get(hObject,'value') ;
set(handles.textrs,'string',num2str(rs)) ;
guidata(hObject,handles) ;


Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 10 Apr 2019
 Accepted Answer

Mustafa - in the callback for the first slider you could try something like
function slider1_Callback(hObject, eventdata, handles)
taper = get(hObject,'value') ;
set(handles.sliderrs, 'Max', taper);
But you would need to add some logic to make sure that the max value you are using (taper) is valid given the minimum value for that other slider else you may see warning messages like
Warning: slider control requires that Min be less than Max
Control will not be rendered until all of its parameter values are valid


Thank you,
how can i say: "if sliderrs max value < 0" in matlab syntax
if get(handles.sliderrs, 'Max') < 0
% do something

Sign in to comment.