How do properties work in Object Oriented MATLAB?

前端 未结 3 644
花落未央
花落未央 2020-11-29 07:05

I am trying to create a MATLAB class with a member variable that\'s being updated as a result of a method invocation, but when I try to change the property within the class

3条回答
  •  忘掉有多难
    2020-11-29 08:07

    You have to remember that syntactically in Matlab, you're probably closer to C, than C++ or Java, at least with respect to objects. So, of you want to change the "contents" of a value object (really just a special struct), you need to return the object from the function.

    Azim was correct to point out that if you want Singleton behavior (which, from your code, you seem to), you need to use a "handle" class. Instances of classes that derive from Handle all point to a single instance, and operate only on it.

    You can read more about the differences between Value and Handle classes.

提交回复
热议问题