Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MATLAB Concatenation Rules for objects

Subject: MATLAB Concatenation Rules for objects

From: <kzelechowski@e3tech.local>

Date: 8 May, 2013 07:59:12

Message: 1 of 5

class (handle (0)) == 'root';
class (libpointer) == 'lib.pointer';
class ([ libpointer, (handle (0)) ]) == 'handle';
% Why? The documentation says: MATLAB does not convert objects to a common
superclass unless those objects derive from a member of a heterogeneous
hierarchy.
% This is not the case:
isa (libpointer, 'math.mixin.Heterogeneous') == 0;
% So what is going on here? Moreover:
numel (superclasses (libpointer)) == 0;
numel (superclasses (handle (0))) == 0;
% So if they were heterogeneous, the superclass would be hidden. I am not
sure how to test for that.

Subject: MATLAB Concatenation Rules for objects

From: Steven_Lord

Date: 8 May, 2013 18:09:57

Message: 2 of 5



<kzelechowski@e3tech.local> wrote in message
news:518a04eb$0$1266$65785112@news.neostrada.pl...
> class (handle (0)) == 'root';

The HANDLE function is undocumented. [The HANDLE _class_ is Abstract and so
cannot be instantiated, so this can't be a call to instantiate an object
using 0 as an input parameter. You must inherit from it to instantiate a
handle object.]

> class (libpointer) == 'lib.pointer';

Yes, libpointer returns a lib.pointer object.

> class ([ libpointer, (handle (0)) ]) == 'handle';
> % Why? The documentation says: MATLAB does not convert objects to a
> common superclass unless those objects derive from a member of a
> heterogeneous hierarchy.

You're calling out one of the four bullets in this section of the
documentation, the last one:

http://www.mathworks.com/help/matlab/matlab_oop/concatenating-objects-of-different-classes.html

There are other bullets that apply to general concatenation of objects.

> % This is not the case:
> isa (libpointer, 'math.mixin.Heterogeneous') == 0;

The name of the base class used to construct a heterogeneous hierarchy is
not math.mixin.Heterogeneous. It is matlab.mixin.Heterogeneous.

> % So what is going on here? Moreover:
> numel (superclasses (libpointer)) == 0;
> numel (superclasses (handle (0))) == 0;
> % So if they were heterogeneous, the superclass would be hidden. I am not
> sure how to test for that.

What specifically are you trying to do? Why are you attempting to use
lib.pointers and the HANDLE function? What's your application?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: MATLAB Concatenation Rules for objects

From: <kzelechowski@e3tech.local>

Date: 9 May, 2013 06:59:06

Message: 3 of 5

I am trying to keep a pointer and numeric values in a 'UserData' property.
I was not using pointers before and the value could be an array but I cannot
add a pointer to an array so I am trying to figure out what is going on and
why. I acknowledge your objection that the function handle is undocumented,
so my example is void, I am unable to come up with another one and I should
not be so nosey.

Thanks,
Chris

Uytkownik "Steven_Lord" napisa w wiadomoci grup
dyskusyjnych:kme4dk$c70$1@newscl01ah.mathworks.com...



<kzelechowski@e3tech.local> wrote in message
news:518a04eb$0$1266$65785112@news.neostrada.pl...
> class (handle (0)) == 'root';

The HANDLE function is undocumented. [The HANDLE _class_ is Abstract and so
cannot be instantiated, so this can't be a call to instantiate an object
using 0 as an input parameter. You must inherit from it to instantiate a
handle object.]

> class (libpointer) == 'lib.pointer';

Yes, libpointer returns a lib.pointer object.

> class ([ libpointer, (handle (0)) ]) == 'handle';
> % Why? The documentation says: MATLAB does not convert objects to a
> common superclass unless those objects derive from a member of a
> heterogeneous hierarchy.

You're calling out one of the four bullets in this section of the
documentation, the last one:

http://www.mathworks.com/help/matlab/matlab_oop/concatenating-objects-of-different-classes.html

There are other bullets that apply to general concatenation of objects.

> % This is not the case:
> isa (libpointer, 'math.mixin.Heterogeneous') == 0;

The name of the base class used to construct a heterogeneous hierarchy is
not math.mixin.Heterogeneous. It is matlab.mixin.Heterogeneous.

> % So what is going on here? Moreover:
> numel (superclasses (libpointer)) == 0;
> numel (superclasses (handle (0))) == 0;
> % So if they were heterogeneous, the superclass would be hidden. I am not
> sure how to test for that.

What specifically are you trying to do? Why are you attempting to use
lib.pointers and the HANDLE function? What's your application?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: MATLAB Concatenation Rules for objects

From: Yair Altman

Date: 9 May, 2013 08:22:09

Message: 4 of 5

<kzelechowski@e3tech.local> wrote in message <518a04eb$0$1266$65785112@news.neostrada.pl>...
> class (handle (0)) == 'root';
> class (libpointer) == 'lib.pointer';
> class ([ libpointer, (handle (0)) ]) == 'handle';
> % Why? The documentation says: MATLAB does not convert objects to a common
> superclass unless those objects derive from a member of a heterogeneous
> hierarchy.
> % This is not the case:
> isa (libpointer, 'math.mixin.Heterogeneous') == 0;
> % So what is going on here? Moreover:
> numel (superclasses (libpointer)) == 0;
> numel (superclasses (handle (0))) == 0;
> % So if they were heterogeneous, the superclass would be hidden. I am not
> sure how to test for that.


handle() basically wraps its input in a UDD handle object. From Donn Shull's explanation (http://undocumentedmatlab.com/blog/introduction-to-udd/#Tools):

    handle is a multifaceted and unique term for The MathWorks. There are both UDD and MCOS handle classes. There is a UDD handle package. In terms of the tools we need, handle() is also an undocumented function which converts a numeric handle into a UDD handle object. Depending on your background you may want to think of handle as a cast operator which casts a numeric handle into a UDD object.

By using handle(), you can thus concatenate objects of different types. This can be very useful, as you have seen.

Matlab always shows the array as having the common type. If the concatenated objects are all alike, then their specific common type is displayed; otherwise, the common type is simply the base UDD handle class, which is basically the superclass you were looking for.

The mechanism you're using may be undocumented, but has worked consistently for the past decade or so, and I suspect (although I can't be certain) it will continue to work in the near future.

Note that a fully documented alternative is to use a cell-array, or a struct:

    userdata = {0, libpointer};

    userdata.numeric = 0; % root
    userdata.pointer = libpointer;

Yair Altman
http://UndocumentedMatlab.com
 

Subject: MATLAB Concatenation Rules for objects

From: Steven_Lord

Date: 9 May, 2013 13:41:03

Message: 5 of 5



<kzelechowski@e3tech.local> wrote in message
news:518b482c$0$26708$65785112@news.neostrada.pl...
> I am trying to keep a pointer and numeric values in a 'UserData' property.

I recommend either a struct array or a cell array (or if you want to get
really crazy, both as with mydata.listOfMatrices below.)

mydata.mypointer = libpointer;
mydata.handleOfRoot = 0;
mydata.listOfMatrices = {magic(4), zeros(7), gallery('moler', 5)};
set(gcf, 'UserData', mydata)
clear mydata
x = get(gcf, 'UserData')

Cell arrays and struct arrays are designed to contain multiple types and
sizes of data independent of one another. When you store two arrays of
different types, sizes, or attributes in an array that is not a cell or
struct, at least one of the arrays is usually going to have to change.

> I was not using pointers before and the value could be an array but I
> cannot add a pointer to an array so I am trying to figure out what is
> going on and why. I acknowledge your objection that the function handle
> is undocumented, so my example is void, I am unable to come up with
> another one and I should not be so nosey.

It's not so much that you were being "nosey", I wanted to see if there was a
way to do what you were really after without using undocumented
functionality like the HANDLE function. I don't really want to discuss
undocumented functionality if I can help it, much to Yair's disappointment
;) It turns out there is a way to achieve your ultimate goal using just
documented functionality, as I mentioned above.

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us