I using pre-existing code in matlab that is organized into classes. Instead of using classdef it uses @folder’s. I’m not entirely sure exactly how it works and its causing me some trouble.
The constructor format is as follows:
function this = crazy_class(varargin)
this.a = [];
this.b = [];
this = class(this, 'crazy_class');
end
I need to add a new property to the class, but if i modify it as so:
function this = crazy_class(varargin)
this.a = [];
this.b = [];
this.newProperty = [];
this = class(this, 'crazy_class');
end
I get the following:
Number of fields for class crazy_class cannot be changed without clear classes.
It doesn’t like me adding a new unspecified property to the class. Fair enough, if there was a classdef, adding a new property would be simple, however I have no idea how to do this with the @folder format.
There is no .m file, or any file for that matter in the folder that specifies any properties for the class. The closest thing I can find are the overloaded functions:
subsasgn.m:
this = builtin('subsasgn', this, selector, value);
subsref.m:
r = builtin('subsref', this, selector);
But that’s it. How does this class know what are valid properties and what aren’t when they aren’t mentioned in any other file. What am I supposed to look for to change this?
Edit: well this is embarrassing… I restarted Matlab and now everything works fine. I thought that by typing the command clear classes, or clear all would have done the trick but I guess it needed a full reboot.
The point is, you must now execute the command “clear classes”, since there are existing class members with the old format. MATLAB told you that fact itself. The properties are defined in the crazy_class.m file.