MATLAB: Is it possible to use the UNIQUE command on an array of handle objects in MATLAB 7.8 (R2009a)

intersectismemberMATLABsetdiffsetxorunique

I have an array of handle class objects. I would like to find the number of unique objects in the array.

Best Answer

This enhancement has been incorporated in Release 2010a (R2010a). For previous product releases, read below for any possible workarounds:
It is not possible in MATLAB to use the UNIQUE function on arrays of the handle class objects. The UNIQUE method only works on arrays of class double.
As a workaround:
- create a "double" method in the custom handle class. This method should take the handle object as an input and give back an object of the class double as an output (in a user defined way). Find an example of how to do this under the heading "Converting DocPolynom Objects to Other Types" in the doc.
- create a unique property in each object (like an ID). Use this property to find the unique number of object instances in the array.
- create a "unique" method for the handle class