How to assign a value using a RADIO Button in the GUI
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to use 2 radio buttons in a GUI in this way:
radiobutton1 -> acceleration = 1; radiobutton2 -> acceleration = -1;
Then I want to use this "acceleration" within other functions that are used by the GUI.
I've no problems with "Edit text", "Push buttons" and others, but I'm struggling with the Radio Button. For example I can use a value with the "Edit text" simply buy writing
value = handles.EDIT_TEXT;
But I'm not able to do the same with a radio button.
Thanks in advance!
댓글 수: 0
채택된 답변
debasish
2012년 6월 20일
1.Create the two radio buttons in a button panel
2.Set the properties of each radio button.(tag,font,string,etc).lets assume tags be 'accel1_radiobutton' and 'accel2_radiobutton'.
Set the tag of button panel to 'acceleration_buttongroup'.
3.Add this line of code to the opening function
set(handles.acceleration_buttongroup, 'SelectionChangeFcn', @acceleration_buttongroup_SelectionChangeFcn);
4.Next,add the following function at the very end of .m file
function acceleration_buttongroup_SelectionChangeFcn(hObject, eventdata)
handles=guidata(hObject);
switch get(eventdata.Newvalue, 'Tag' )
case 'accel1_radiobutton'
handles.value= 1; %%any handle where value is to be stored
case accel2_radiobutton
%%similarly set the value '-1'
댓글 수: 5
Christoforos Rekatsinas
2014년 10월 7일
Hi guys. So far so good. But i have a problem thow. The handles structure isnt gettin updateed with the new variable after exiting the buttongroup function. ANy recomendations?
추가 답변 (1개)
Future Science
2012년 6월 20일
댓글 수: 3
Preshma Linet Pereira
2015년 3월 25일
thank you @walter roberson! really helped! was stuck with the same problem.
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!