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?

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 6 月 4 日

0 投票

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 ExchangeInteractive 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