IsField method not returning correct value

조회 수: 12 (최근 30일)
Tim Lenardo
Tim Lenardo 2015년 4월 10일
편집: Paul 2023년 12월 13일
The isfield() method is not currently working for me. Check out this output from the console:
K>> TFORM
TFORM =
projective2d with properties:
T: [3x3 double]
Dimensionality: 2
K>> TFORM.T
ans =
0.9889 -0.0068 -0.0000
0.0003 0.9918 -0.0000
3.7452 5.5412 1.0000
K>> isfield(TFORM, 'T')
ans =
0
I can see that my object (TFORM) is there, and that it has a field named 'T'. However, when I run isfield(TFORM, 'T'), I get a 0 result. What gives?
*Edit*
I'm running R2015a (8.5.0.197613), on a 64-bit Mac.
AND
I was able to work around this by using:
any(strcmp(fieldnames(TFORM),'T'))
In place of:
isfield(TFORM, 'T')

채택된 답변

David Foti
David Foti 2016년 4월 8일
isfield finds fields in structs. The isprop function finds properties in objects.
  댓글 수: 8
Steven Lord
Steven Lord 2023년 12월 12일
In my opinion this behaviour of isfield is the source of unexpected behaviour of code more often than not in case of handling of structs and classes.
If you feel strongly about this, you could send a bug report or enhancement request to Technical Support directly using this link. Be sure to explain your use case for why we should change this behavior that has been in the product literally for decades. [I just checked and in one of the older releases I can run on this machine, release R11 which was released in January 1999, isfield(1, 'field') returns 0.]
Paul
Paul 2023년 12월 12일
편집: Paul 2023년 12월 13일
My issue is that the Input Arguments section of the doc page strongly implies (at least to me) that the only valid input for the first argument is a structure array. Insofar that it seems the intent of the function is to accept any type of input, it seems to me that should be clearly indicated in the Input Arguments section that describes S.
I don't feel strongly enough about this to file a suggestion with the doc support folks.

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

추가 답변 (0개)

카테고리

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