Using radio button problem?

3 views (last 30 days)
Mahmoud
Mahmoud on 19 Jun 2014
Answered: Geoff Hayes on 19 Jun 2014
Hello, I have designed a GUI that calculates a certain value when I click the push button called "Calculate" using a values that the user will enter, now I want to create a radio button that when its selected and then the calculate button is pressed the GUI will use a different equation to calculate the same value for the same values entered? Any help is much appreciated

Answers (1)

Geoff Hayes
Geoff Hayes on 19 Jun 2014
I think that your question title is a little misleading since there is no problem with the radio button, rather you are unsure on how to implement this functionality.
The link http://www.mathworks.com/help/matlab/creating_guis/add-code-for-components-in-callbacks.html#f10-1001546 describes the Button Group panel which can be used (for example) to manage one or more radio buttons. So you would create the button group widget, and add your radio button widgets inside of this panel. As described in the link, the SelectionChangeFcn callback can be created for the button group widget which will fire whenever the user presses a different radio button.
I don't think that that is quite what you want to do since you want this selection to be invoked whenever the user presses the Calculate button. The link alludes to what will solve your problem with the following note
The button group's SelectedObject property contains a handle to the button that user selected. You can use this property elsewhere in your GUI code to determine which button the user selected.
So in your calculate button callback, you could write something like the following
% get the handle to the selected radio button in the button group uipanel1
hRadioBtn = get(handles.uipanel1,'SelectedObject');
% based on the string value/tag for this radio button, use a different equation
eqnStr = get(hRadioBtn,'String');
if strcmpi(eqnStr,'Equation 1')
% do equation one
elseif strcmpi(eqnStr,'Equation 2')
% do equation two
%etc.
end
Try the above and see what happens!

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!