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 ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Determining 'classname' such that isa(v,'classname') will be true
Posted: Apr 18, 2013 9:48 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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


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

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

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.