How to set togglebutton by another togglebutton

1 view (last 30 days)
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

Accepted Answer

Geoff Hayes
Geoff Hayes on 4 Apr 2020
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.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!