필터 지우기
필터 지우기

Make a calculator display an error message for non-numerical values.

조회 수: 2 (최근 30일)
Kokalz
Kokalz 2012년 7월 10일
I am trying to program a simple calculator with 2 "edit text" windows. I want it to display an error dialog for non-numerical values. I used the following function at the "edit text" gui callback:
endb=str2num(get(hObject, 'String'));
if isnan(b)
errordlg('Input must be a number', 'Error')
end
handles.edit1=b;
guidata(hObject,handles)
but it only displays the error message if I type in 'nan'. How to make it appear for all non-numerical values?
  댓글 수: 1
Jan
Jan 2012년 7월 10일
If you set a breakpoint in the 2nd line, you can check, what STR2NUM replies for your non-numerical value. STR2DOUBLE would be safer.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by