Show a ERRORDLG when only one RADIOBUTTON is pressed, all controlled with a Togglebutton
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Suhas Maddi
2020-6-19
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 个评论
Suhas Maddi
2020-6-19
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!