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?

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 6월 4일
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에 대해 자세히 알아보기

질문:

2016년 5월 30일

답변:

2016년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by