How to pass a function to a switch in a button group created using the manual in MATLAB?

I created a button group with four radio buttons and a button using the manual.

There are four functions: one for each radio button, written separately.

  • How can you call these functions with the appropriate switches.
  • When a button is pressed, the function associated with the active radio button should be executed.
+3
source share
2 answers

Button Group Callback Solution: SelectionChangeFCN

( - > SelectionChangeFcn) uipanel. eventdata . eventdata - :

  • EventName
  • OldValue
  • NewValue

, eventdata.NewValue;

function uipanel1_SelectionChangeFcn(hObject,eventdata,handles)
...
newButton=get(eventdata.NewValue,'tag');
switch newButton
     case 'radiobutton1'
         % code for radiobutton 1 here
     case 'radiobutton2'
         % code for radiobutton 2 here
     ...
end
...

-

function button1_Callback(hObject,eventdata,handles)
h_selectedRadioButton = get(handles.uipanel1,'SelectedObject');
selectedRadioTag = get(h_selectedRadioButton,'tag')
switch selectedRadioTag
   case 'radiobutton1'

   case 'radiobutton2'
   ...
end

MATLAB Handle Graphics .

+6

Crash GUI ... :

guide, mygui.fig M mygui.m. mygui.m . , , . , guidata (hObject, handle).

, ( , , , ), :

function radiobutton1_Callback(hObject, eventdata, handles)
if get(handles.hObject,'Value')
    set(handles.radiobutton2,'Value',0)
else
    set(handles.radiobutton2,'Value',1)
end
guidata(hObject,handles);

function radiobutton2_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
    set(handles.radiobutton1,'Value',0)
else
    set(handles.radiobutton1,'Value',1)
end
guidata(hObject,handles);

, :

set(handles.radiobutton1,'Value',1)
set(handles.radiobutton2,'Value',0)
+2

Source: https://habr.com/ru/post/1740818/


All Articles