How to know if a radio button is selected or not?

A
Alexander · Feb 26, 2021 · 1.9K views
Question
I have one GUI with 4 Radio Buttons and one Push Putton. All of them are in one Button Group.   I want, if the user didn't select any radio button, then the Push Button will do code-A, and if the user selected any of the radio buttons, then the Push Button will do code-B.   Any idea how to do that?   The code below is in my Push Button Function   if %user did not select any radio button, then do this else %do this if a user selected a radio button switch get(get(handles.uipanel4,'SelectedObject'),'Tag') case 'radiobutton5', line_type = 'imline'; case 'radiobutton6', line_type = 'impoint'; case 'radiobutton7', line_type = 'imfreehand'; case 'radiobutton8', line_type = 'impoly'; end  
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Aug 24, 2026
Anyway what you can do is in the callback function of your pushbutton, write this if else statement
 
 
if (get(handles.radiobutton1,'Value') == 0 && get(handles.radiobutton2,'Value') == 0 &&  get(handles.radiobutton3,'Value') == 0 && get(handles.radiobutton4,'Value' == 0)

    %user did not select any radio button, then do this
  else
    %do this if a user selected a radio button

      switch get(get(handles.uipanel4,'SelectedObject'),'Tag')

      case 'radiobutton5',  line_type = 'imline';

      case 'radiobutton6',  line_type = 'impoint';

      case 'radiobutton7',  line_type = 'imfreehand';    

      case 'radiobutton8',  line_type = 'impoly';
  end
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!