Show a ERRORDLG when only one RADIOBUTTON is pressed, all controlled with a Togglebutton

1 view (last 30 days)
I am making a graphical interface, and I want that when I press the toggle button "RESULTADOS", It will get an error if I only have 1 radio button pressed.
Of course, if I press two or more radio buttons, it won't show me an error.
this is my code:
function togglebutton3_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(handles.radiobutton1,'Value') == 1
elseif get(handles.radiobutton2,'Value') ==0
elseif get(handles.radiobutton3,'Value') ==0
else get(handles.radiobutton4,'Value') ==0
errordlg('fill in at least two fields','Error','Ok','Ok')
end
It doesn't show me anything in the command window.
I don't know exactly how to write the code to show me error when I only press a single radio button.
Any recommendation?

Answers (1)

Suhas Maddi
Suhas Maddi on 19 Jun 2020
Hii Joshua, I think, you are trying to show an error dialog when only one of the radio buttons is pushed.
To acheive this, you can keep a global count variable and add 1 to the count when ever a button is pushed and make the count zero at the end of the function.If the count is 1,then you can raise an error dialog and then reset the count at the end.
The code may look like this :
count=0; %Global Variable
function togglebutton3_Callback(hObject, eventdata, handles)
if get(handles.radiobutton1,'Value') == 1
count=count+1;
end
...
...%write conditions as per requirement
count=0; %resetting the count value
end
I hope this helps you.
  2 Comments
Joshua Ztradivari
Joshua Ztradivari on 19 Jun 2020
and if I don't select any radio button, but I still want that, because I don't select any radio button, I will get the errordlg when I press the toogle button,
How would I modify the code?
I am new to graphical interfaces. I appreciate your responses.
Suhas Maddi
Suhas Maddi on 19 Jun 2020
If I understand you correctly,you only want to get the error dialog when only one radio button is pushed,then you can modify the code as :
if count==1
errordlg('fill in at least two fields','Error','Ok','Ok');
end
I hope this helps you.

Sign in to comment.

Categories

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

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!