Question regarding function using radiobutton status

Lets say I have three radio buttons. If 1 is pressed, then variables x,y,z are certain values. If 2 is pressed, then variables x,y,z are different values, etc.
How would I write a function that outputs those variables and use it within the GUI code?

 采纳的回答

Greg - consider placing your three radio buttons in a button group panel and assigning a SelectionChangeFcn callback to this panel. Whenever the user selects a radio button, this callback will fire and you will be able to changes the variables as you see fit based on the selected radio button
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
selectedRadioBtnStr = get(hObject,'String');
if strcmpi(selectedRadioBtnStr, 'Radio Button 1')
handles.x = 1;
handles.y = 2;
handles.z = 3;
elseif strcmpi(selectedRadioBtnStr, 'Radio Button 2')
handles.x = 11;
handles.y = 21;
handles.z = 31;
elseif strcmpi(selectedRadioBtnStr, 'Radio Button 3')
handles.x = 111;
handles.y = 211;
handles.z = 311;
end
guidata(hObject,handles);
We then save those changes to the handles structure using guidata. See the attached for an example.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by