Not getting Error message

조회 수: 1 (최근 30일)
Avinav Kumar
Avinav Kumar 2021년 9월 23일
답변: Walter Roberson 2021년 9월 23일
I am trying to get an error message if my a value is left empty by user. But i am not getting the same. If someone can help.My code is as follows.
function Run_Callback(hObject, eventdata, handles)
% hObject handle to Run (see GCBO)
% eventdata reserved - to be defined in edit1 future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=str2double(get(handles.edit1,'string'));
b=str2double(get(handles.edit2,'string'));
c=str2double(get(handles.edit3,'string'));
d=str2double(get(handles.edit4,'string'));
e=str2double(get(handles.edit5,'string'));
f=str2double(get(handles.edit6,'string'));
g=str2double(get(handles.edit7,'string'));
h = a *((b/c)*(d/e)^2*(f/g))^(1/5);
if isempty(a)
errordlg('Please enter value ofDreference','Error Code I');
else
set(handles.edit8,'string',num2str(h));
end

답변 (1개)

Walter Roberson
Walter Roberson 2021년 9월 23일
AnEmptyString = '';
str2double(AnEmptyString)
ans = NaN
When you str2double() something empty, you get NaN, not empty. You need to check the result of the get() if you want to distinguish between the user entering nothing, or the user entering 'NaN', or the user entering something that is not number-like.

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by