The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

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

"Steven_Lord" <> wrote in message <kkotjj$pu7$>...
> "Paul " <> wrote in message
> news:kknj76$2el$

> > "Steven_Lord" <> wrote in message
> > <kkmaj0$t60$>...

> *snip*

> > 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.

> That's a reasonable expectation, but it does only look at direct "parents"
> of the class. You need to ask the parents for information about the
> grandparent classes and so on back through the object's "family tree."

> > 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.

> If you want to check that the input is either an SS or a TF or a ZPK object,
> either:
> if ~(isa(in, 'ss') || isa(in, 'tf') || isa(in, 'zpk'))
> or (if you don't want to accept subclasses of one of those three classes)
> if ~ismember(class(in), {'ss', 'tf', 'zpk'})
> would work.
> One potential problem with checking for the superclass is that your function
> would not only accept SS or TF or ZPK objects but would accept ANY object
> that inherits from numlti. For instance, a RandStream object is a handle
> object (and subclasses the handle class) but checking:
> isa(inputExpectedToBeARandStream, 'handle')
> is not sufficient to ensure it can behave like a RandStream object.
> RandStream objects can do certain things (generate random numbers, for
> example) that not all handle classes can do.

> > 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.

> Hmm ... I just learned something. I did not know of the existence of this
> function until I did a search:
> Note that this is not necessarily going to give you the whole hierarchy; if
> there are any Hidden classes they will not be listed. Using this on an ss
> object does list lti. [And no, there is no corresponding SUBCLASSES
> function. Classes _must_ know about their superclasses since the
> specification of the classes from which they inherit are explicitly part of
> their class definition file; they don't necessarily know who their
> "children" are.]
> --
> Steve Lord
> To contact Technical Support use the Contact Us link on


Thanks for the response about the superclasses function. I guess I wasn't the only one who thought there was a need for something like this ;). However, I am disappointed that this wasn't easy to find in the documenation (at least for me). I think that starting here:

should have made this easy to find, i.e., the class of an object and its superclasses seem like pretty fundamental information about a class. Furthermore , the doc page for class

should include superclasses in the See Also list (especially since it points to metaclass)
and the doc page for superclasses should include class in its See Also list, and the doc page for meta.class should include a link to superclasses in the defintion of the SuperClassList.

Incidentally, it seems to me that superclasses is in the wrong part of the doc anyway. It's over in "Defining Matlab Classes" when in fact it's not a function that's used to actually define a matlab class.

Thanks for all of the help, it is much appreciated.


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.