Get information of property type of object properties (i.e. 'dependent')

Hello,
I often use a subfunction to compare if two objects are equal. This subfunction simply compares every property for same numbers, strings and so on. My objects have some dependent properties which need a lot of time to be calculated. It would not be necessary to compare the dependent properties to see if objects are equal.
Is there a possibility to find out, if properties are "real" properties before accessing them?
Thaks for any help!
Staffan

추가 답변 (3개)

Daniel Shub
Daniel Shub 2012년 3월 1일

0 개 추천

Isn't the current behavior of your subfunction what isequal does? Why not overload isequal for your class? Presumably in the context of your classdef you know which properties are dependent.

댓글 수: 2

isequal compares numbers only. what i need is comparing any datatype stored in any field of any object or struct. hence i use a subfunction wich recursively compares data according to its type (isequal, strcmp, length, ...). thanks anyways!
Your other answer seems to suggest that you no longer believe that isequal only works with numbers. If this is the case, please consider editing (requires deleting and reposting) your comment to help others in the future.

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

per isakson
per isakson 2012년 3월 13일

0 개 추천

With R2010b helps says:
When comparing handle objects, use eq or the == operator to test whether objects are the same handle. Use isequal to test if objects have equal property values, even if those objects are different handles.

댓글 수: 1

I think is should be a comment to my answer, and not a new answer. Also, why no love with an upvote. In this case I think an upvote could help others in the future realize the comment by Staffan isn't correct.

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

Staffan
Staffan 2012년 3월 14일

0 개 추천

ok, you are rigth, isequal (withequalnans) works on objects. Dont know, why I missed that when I wrote my own function. However, my function also outputs the property, which differs and accept input (strings) for fieldnames that should not be compared. Furthermore it deals with the 0.1+0.1+0.1 == 0.3 problem.
If anybody need such a function, please tell me.

댓글 수: 1

I think this should either be a comment to per's answer or a comment to my answer. Your "enhancements" seem to be asking a much different question. I think it would probably be reasonable to post your function as none of the answers provide working code segments.

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

카테고리

도움말 센터File Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by