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

More Answers (3)

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 Comments

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.

Sign in to comment.

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 Comment

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.

Sign in to comment.

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 Comment

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.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!