필터 지우기
필터 지우기

Syntax Issue in If Statement Using Handles

조회 수: 1 (최근 30일)
Jay
Jay 2016년 4월 11일
댓글: Jay 2016년 4월 11일
I am trying to write an if statement in a function, to determine if the handles values are of valid type, as per the stipulation in the texts written above said handles in the GUI.
For handle 'edit1' I have written:
if handles.edit1 == NaN
set(handles.edtit2, 'enable', 'off') && set(handles.listbox1, 'string', 'Date must be of stated syntax')
else set(handles.edit2, 'enable', 'on')
end
During runtime the code skips to else not flagging
if handles.edit1 == Nan
as true thus setting the 'handles.edit2' off and having the error showing in listbox1.
What is wrong with my if statement?

채택된 답변

Stephen23
Stephen23 2016년 4월 11일
편집: Stephen23 2016년 4월 11일
You cannot test for equality of NaN's, because as the documentation clearly states, NaN's are not equal to each other. Use isnan instead:
>> handles.edit1 = NaN;
>> handles.edit1 == NaN
ans =
0
>> isnan(handles.edit1)
ans =
1

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 4월 11일
Use ishghandle() instead testing for NaN .
  댓글 수: 1
Jay
Jay 2016년 4월 11일
Thanks Walter,
I will see if that does what I need.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by