필터 지우기
필터 지우기

??? Undefined function or method 'isnan' for input arguments of type 'struct'.

조회 수: 11 (최근 30일)
I have a structure array, 'AMap'. The elements of 'AMap', which are called 'fitresults', are most often structre arrays themselves, but sometimes they are supposed to be equal to NaN, such as can be seen and verified in the command window:
>> AMap(8,1).fitresults
ans =
NaN
>> isnan(AMap(8,1).fitresults)
ans =
1
But when I try to use 'isnan' in an if statement in a forloop in a function,
if(isnan(AMap(i,j).fitresults)==0)
I get the error:
??? Undefined function or method 'isnan' for input arguments of type 'struct'.
but as you can see 'isnan' must be defined for structs since I can use isnan on a struct in the command window. What gives? How can I get around this?
thanks in advance,
Rory

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 11일
You only tested isnan() for the case where AMap(8,1).fitresults is NaN, and did not test it for the case where it is a structure instead.
I suggest that you change your test to
if isstruct(AMap(i,j).fitresults)

추가 답변 (1개)

Rory Staunton
Rory Staunton 2011년 5월 11일
When the value of AMap(i,j).fitresults is NaN, then isnan works, because fitresults is not a struct.
When the value of AMap(i,j).fitresults is a struct array, then 'isnan' complains, because it is a struct, and 'isnan' can't work on structs.
My solution is to use 'isstruct' instead. It will give 0 when fitresults = NaN, and 1 when it is a struct.
For my purposes this will suffice...

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by