Filter löschen
Filter löschen

Update GUI based on values chosen in a Radio Button Group

4 Ansichten (letzte 30 Tage)
Benjamin Yankelitis
Benjamin Yankelitis am 13 Apr. 2020
Kommentiert: Rik am 14 Apr. 2020
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!

Antworten (1)

Kevin Hellemans
Kevin Hellemans am 14 Apr. 2020
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 Kommentar
Rik
Rik am 14 Apr. 2020
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''))');

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by