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!