Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I get the selected value of radio button?

I am not matlab programmer but I need to create an interface using matlab! This qusetion should be very easy for matlab programmers :)

I have an interface which contains radio button group panel "OperationPanel" ,4 radioButtons inside it which names are "addBtn, subBtn, divBtn, mulBtn" and I have command button, I want when I click over the button to get the value of the selected radioButton

What is the commad I should use ? I google it and found that if I make

get(handles.NewValue,'Tag');

I tired it but it doesn't work!! Can I hava some help!

like image 812
palAlaa Avatar asked Jan 07 '11 10:01

palAlaa


People also ask

How do I get the selected radio button value in Salesforce?

To retrieve the values when the selection is changed, use the onchange event handler and call event. getParam("value") .

How do I get the selected radio button label?

To label a radio button, add a <label> element after the <input> element and insert a for attribute with the same value as the id of the associated <input> element. Then, write your label text in the <label> tag.

How do I get the value of a radio button in react?

To set the default checked value of a radio button in React: Store the radio button value in the state. Initialize the state to the value of the default checked radio button. Set the checked property on each radio button conditionally, e.g. checked={selected === 'yes'} .

Can radio button have value?

Radio buttons don't participate in constraint validation; they have no real value to be constrained.


2 Answers

Here's a quick example to illustrate how to get the value of a radio-button group component:

function simpleGUI
    hFig = figure('Visible','off', 'Menu','none', 'Name','Calculator', 'Resize','off', 'Position',[100 100 350 200]);
    movegui(hFig,'center')          %# Move the GUI to the center of the screen

    hBtnGrp = uibuttongroup('Position',[0 0 0.3 1], 'Units','Normalized');
    uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off', 'Position',[15 150 70 30], 'String','Add', 'Tag','+')
    uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off', 'Position',[15 120 70 30], 'String','Subtract', 'Tag','-')
    uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off', 'Position',[15  90 70 30], 'String','Multiply', 'Tag','*')
    uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','off', 'Position',[15  60 70 30], 'String','Divide', 'Tag','/')

    uicontrol('Style','pushbutton', 'String','Compute', 'Position',[200 50 60 25], 'Callback',{@button_callback})

    hEdit1 = uicontrol('Style','edit', 'Position',[150 150 60 20], 'String','10');
    hEdit2 = uicontrol('Style','edit', 'Position',[250 150 60 20], 'String','20');
    hEdit3 = uicontrol('Style','edit', 'Position',[200  80 60 20], 'String','');

    set(hFig, 'Visible','on')        %# Make the GUI visible

    %# callback function
    function button_callback(src,ev)
        v1 = str2double(get(hEdit1, 'String'));
        v2 = str2double(get(hEdit2, 'String'));
        switch get(get(hBtnGrp,'SelectedObject'),'Tag')
            case '+',  res = v1 + v2;
            case '-',  res = v1 - v2;
            case '*',  res = v1 * v2;
            case '/',  res = v1 / v2;
            otherwise, res = '';
        end
        set(hEdit3, 'String',res)
    end
end

screenshot

Obviously you could add more validations on the input numbers and so on...

like image 188
Amro Avatar answered Oct 12 '22 20:10

Amro


Have you set handles to the hOjbect? Also don't forget to update the handle after processing the radio button event. Have you looked at this Matlab GUI Tutorial? Scroll down to Part 3 step 5 to see the following example code for three radio buttons:

function fontSelect_buttongroup_SelectionChangeFcn(hObject, eventdata)

%retrieve GUI data, i.e. the handles structure
handles = guidata(hObject); 

switch get(eventdata.NewValue,'Tag')   % Get Tag of selected object
    case 'fontsize08_radiobutton'
      %execute this code when fontsize08_radiobutton is selected
      set(handles.display_staticText,'FontSize',8);

    case 'fontsize12_radiobutton'
      %execute this code when fontsize12_radiobutton is selected
      set(handles.display_staticText,'FontSize',12);

    case 'fontsize16_radiobutton'
      %execute this code when fontsize16_radiobutton is selected  
      set(handles.display_staticText,'FontSize',16);
    otherwise
       % Code for when there is no match.

end
%updates the handles structure
guidata(hObject, handles);
like image 23
gary Avatar answered Oct 12 '22 21:10

gary