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

 採用された回答

Honglei Chen
Honglei Chen 2012 年 3 月 1 日

1 投票

1 件のコメント

Staffan
Staffan 2012 年 3 月 13 日
Thanks, that works. Allthough this also takes some time...

サインインしてコメントする。

その他の回答 (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 件のコメント

Staffan
Staffan 2012 年 3 月 13 日
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!
Daniel Shub
Daniel Shub 2012 年 3 月 14 日
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 件のコメント

Daniel Shub
Daniel Shub 2012 年 3 月 14 日
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 件のコメント

Daniel Shub
Daniel Shub 2012 年 3 月 14 日
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 ExchangeArgument Definitions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by