How to set togglebutton by another togglebutton

조회 수: 7 (최근 30일)
Miroslav Jiránek
Miroslav Jiránek 2020년 4월 4일
댓글: Miroslav Jiránek 2020년 4월 4일
Hello guys!
I've 3 togglebuttons in one panel and I would like to set each togglebutton so, that if one of the togglebutton is set to 'Max' value, then the other two togglebuttons are going to be in 'Min' value. I was trying to do something like this in tutorials which I've founded on the forum, but it didnt helped a lot. Can you tell me where is the problem? Thank a lot
function TB_low_ZV_Callback(hObject, eventdata, handles)
hustota_ZV_LOW = get(hObject, 'Value');
if hustota_ZV_LOW == get(hObject, 'Max') %if this button is set to 'Max', change button color and set other two buttons to 'Min'
set(handles.TB_low_ZV,'Backgroundcolor','g');
%setting other buttons
set(handles.TB_med_ZV, 'Value', 'Min'); %turn off toggle buton
TB_med_ZV_Callback(handles.TB_med_ZV, eventdata, handles)
set(handles.TB_high_ZV, 'Value', 'Min'); %turn off toggle buton
TB_high_ZV_Callback(handles.TB_high_ZV, eventdata, handles)
else
set(handles.TB_low_ZV,'Backgroundcolor',[0.94, 0.94, 0.94])
end

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 4일
Miroslav - one problem is with the two lines
set(handles.TB_med_ZV, 'Value', 'Min'); %turn off toggle buton
and
set(handles.TB_high_ZV, 'Value', 'Min'); %turn off toggle buton
. If you want to set them to the minimum value for that toggle button, then you would do
set(handles.TB_med_ZV, 'Value', get(handles.TB_med_ZV, 'Min'));
set(handles.TB_high_ZV, 'Value', get(handles.TB_high_ZV,'Min'));
You need to get the min property so that you can set the value to it. Or, just set use the values of 0 (off) or 1 (on) to set the state of the button.

추가 답변 (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