1
votes

I've been building a number of classes in matlab and recently discovered that certain functions don't behave all to well with my classes. All my objects inherit from the handle superclass

For example :

  • finobj : I can't find any of my objects, Does my base object need to be a child of the matlab Root ? How do I set this up ?

  • clear : Clearing the environment and re-instnatiating my object tree produces a warning if I've changed the properties of the lower objects, possibly I need a destroy method ?

I see here http://blogs.mathworks.com/videos/2008/07/07/advanced-matlab-class-system-for-oop-in-matlab-introduction/ that one is expected to overload some of the operations but surely I'm not expected to do so for each object ?

My main question is what do I have to define for my code to behave in a sensible manner ?

2
Try clear classes instead of just clear maybe? - learnvst
I have a tree structure and if I clear all, modfiy one of the leaf objects and rebuild the tree i get notified that the object was modified, so I was wondering if i needed to implement my own delete methods or not. - Carel
Turns out close all does the trick, mathworks.com/help/techdoc/matlab_oop/brzqjky.html - Carel

2 Answers

0
votes

findobj is for handle graphics objects, not your user-defined objects. Thus, it won't find your objects (why would you want to find them in the first place?).

clear affects variables, clear classes affects also class definitions. Note that in earlier versions of Matlab, clear classes also cleared all the breakpoints.

Subclasses inherit everything from superclasses (including static methods). There is no need to overload anything if you don't want to modify that particular functionality in your subclass.

If you want to have your code behave in a sensible manner, you have to design it well. How exactly you have to design it depends very much on the problem your code is supposed to solve.

0
votes

As it turns out there are a number of classes one can inherit from.

  • hgsetget : Provides the functionality I wanted in the original question, this is a larger class then plain handle.
  • handle : Bare Bones Class, doesn't work with findobj, get or set.
  • Dynamic Props : Don't know too much about it, I'll update later on.

I don't know if I've missed something but there doesn't appear to be a comprehensive list of possible classes in matlab that one can inherit from, indicating pro's con's of each.