Do I have to put get/set methods in the class definition in matlab ?

class, getter-setter, matlab

Solution

Yes, if you use property set and get access methods (in fact any method with a dot in the name), you must include them within the `classdef` file, not in separate files. See the documentation.

However, if you have have a special reason to want to put as much as possible in separate files, you can define methods `getMyProp` and `setMyProp` in separate files, and then within the `classdef` file have the `get.myProp` and `set.myProp` functions call them.

Problem

Is one forced to place all get and set functions in the class definition file in Matlab ? I'm asking since this really makes the file a bit messy and defeats the purpose of having a class definition folder.

Original source