Show a ERRORDLG when only one RADIOBUTTON is pressed, all controlled with a Togglebutton
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Suhas Maddi
el 19 de Jun. de 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 comentarios
Suhas Maddi
el 19 de Jun. de 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.
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!