Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Determining 'classname' such that isa(v,'classname') will be true
Replies: 5   Last Post: Apr 22, 2013 11:33 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Paul

Posts: 17
Registered: 5/18/11
Re: Determining 'classname' such that isa(v,'classname') will be true
Posted: Apr 17, 2013 9:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Steven_Lord" <slord@mathworks.com> wrote in message <kkmaj0$t60$1@newscl01ah.mathworks.com>...
>
>
> "Paul " <paulremovethispartjackson@jhuapl.edu> wrote in message
> news:kkki9r$s7c$1@newscl01ah.mathworks.com...

> > Given an object v of a class, how can I determine all possible classname
> > such that isa(v,'classname') will return true? For example, consider the
> > following:
> >
> > h=ss(1,1,1,1);
> > class(h)
> > mc=metaclass(h);
> > mc.SuperclassList.Name
> > L1=isa(h,'ss'); % returns true, understandable
> > L2=isa(h,'numlti'); % returns true, understandable
> > L3=isa(h,'StateSpaceModel'); % returns true, understandable
> > L4=isa(h,'lti'); % returns true, how would I have known?
> > [L1 L2 L3 L4]
> >
> > ans =
> > ss

>
> This comes from class(h)
>

> > ans =
> > numlti
> >
> > ans =
> > StateSpaceModel

>
> These two come from the _comma-separated list_ mc.SuperclassList.Name.
>

> > ans =
> >
> > 1 1 1 1
> >
> > I just stumbled on 'lti' returning true for this case. How could I have
> > found that programatically?

>
> Note that while mc is a scalar meta.class object, mc.SuperclassList is a
> vector of meta.class objects. ss directly inherits from numlti and
> StateSpaceModel. But if you look at the SuperclassList for each of the
> elements of the mc.SuperclassList vector of objects, you'll see that numlti
> inherits from lti while StateSpaceModel also inherits from another class.
> You can walk your way up the inheritance tree using the meta class objects
> and their SuperclassList properties until all the meta class objects you
> reach have empty SuperclassList properties.
>

> > In general, is there some function that has a functionality like:
> > c = whatis(v); % returns cell array c such that isa(v,c{i}) is true

>
> Not directly, but you could write one to walk the whole tree. It wouldn't be
> that difficult.
>
> Are you planning to do something tricky and/or clever with this information?
> Or is it more something that made you curious?
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Steve,

I missed in the doc that SuperclassList contains only the classes from which the object inherits *directly*. For some reason I thought it would return all of the parents.

I don't think I was trying to do something tricky or clever. I have a function that can take either an ss or tf or zpk object as input and wanted to do a simple error check, like "if ~isa(in,'numlti')", but couldn't find a clear description in the doc for the common class from which those three inherit (there is a diagram in the Control System Toolbox documentation, but it's not what I would think of as an inhertiance tree and doesn't even contain the term 'numlti'). So I started exploring the use of class(h) and metaclass to figure it out myself.

Maybe a whatis type of function would be useful in general to provide insight into a class hierarchy? I don't really use OOP in Matlab, and so don't know if there are any good use-cases, other than the one I described above.

Thanks,
Paul



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.