It appears that the dataset superclass has a subsref method defined, and hence is inherited by your subclass mydataset. When the class possesses a subsref method, indexing behavior outside class methods (e.g., at the command line) is different from inside them.
Inside the classdef, dot indexing never calls the class' subsref method. Instead, it is always interpreted as an attempt to access properties and methods of the class. In the first version of the mydataset classdef that you posted, Field1 and Field2 are not properties of the class (they are just data stored in some protected superclass property), so your attempt to access them by dot-indexing inside a class method fails. To get at the data, you must do so indirectly through explicit calls to subsref (as in your workaround), or whatever other indirect access methods the dataset class might have defined.
Outside the class definition, indexing expressions always call the class' subsref method, in this case subsref@dataset or subsref@mydataset, if you chose to overload it, and do whatever subsref dictates.
It's not entirely clear to me what indexing behavior you are trying to achieve, and where you want to achieve it. "Where" is important because indexing behavior cannot be the same both inside and outside the classdef. However, be aware that you are always free to invoke class methods in functional form, i.e.,
classmethod(obj,arg1,arg2,...
will always work whether inside the class definition or elsewhere, whereas outside the class definition
obj.classmethod(arg1,arg2)
will invoke subsref@mydataset.
Best Answer