How to set togglebutton by another togglebutton

5 次查看(过去 30 天)
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