필터 지우기
필터 지우기

Update GUI based on values chosen in a Radio Button Group

조회 수: 4 (최근 30일)
Benjamin Yankelitis
Benjamin Yankelitis 2020년 4월 13일
댓글: Rik 2020년 4월 14일
A happy and safe quarantine to all :)
I am attempting to make a GUI to model a simulation of a crane moving from an initial position to a final position based on the previous button chosen and the new button selected (Button 0 was selected at startup, user selected Button 3, crane will travel 3 feet). My button group is called 'position' and each button is tagged as 'pos0', 'pos1', and so forth.
What is the easiest way to generate a value from this group so a simple subtraction can be formed such as x=NewValue-OldValue each time a new button is selected, so the distanced needed to be traveled can be imported into the controls functions already coded?
Thank you!

답변 (1개)

Kevin Hellemans
Kevin Hellemans 2020년 4월 14일
Hi,
One possibility (might not be the most elegant solution) is to read all radio buttons in a single variable. When you create your GUI, you'll need to add the radio button handles to the gui handles and then set the callback for each radio button to read the gui handles, so you can extract the values. for instance:
gui_handles = guidata(your_figure_handle);
val = '100';
val(1) = num2str(get(gui_handles.pos0,'Value'));
val(2) = num2str(get(gui_handles.pos1,'Value'));
val(3) = num2str(get(gui_handles.pos2,'Value'));
val = find(val=='1');
The val variable now tells you which radio button is selected, you can then use a lookup table/ switch case to handle specific selected values.
  댓글 수: 1
Rik
Rik 2020년 4월 14일
You can make your life a lot easier by setting the Max property of your radio buttons to a specific value. That way you don't even need a lookup table. I would also suggest putting the handles in an array instead of using numbered field names.
figure(1),clf(1)
uicontrol('Style','radio','Max',10,...
'Units','Normalized','Position',[0.2 0.2 0.6 0.6],...
'String','Click to display value in command window',...
'Callback','clc,disp(get(gcbo,''Value''))');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by