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

조회 수: 2 (최근 30일)
Hi,
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)) ;
guidata(hObject,handles)
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) ;

채택된 답변

Geoff Hayes
Geoff Hayes 2019년 4월 10일
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.texttaper,'string',num2str(taper));
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
  댓글 수: 2
Mustafa Uysal
Mustafa Uysal 2019년 4월 10일
Thank you,
how can i say: "if sliderrs max value < 0" in matlab syntax
Geoff Hayes
Geoff Hayes 2019년 4월 11일
try
if get(handles.sliderrs, 'Max') < 0
% do something
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by