Suppose I have a constructor called 'myclass(arg1, arg2)', with fields f1, f2. Mathworks says it should be defined like this:
function obj = myclass(arg1, arg2) if nargin==0 obj.f1 = ... obj.f2 = ... obj = class('obj', 'myclass'); elseif isa(arg1, 'myclass') obj = arg1; else obj = normal constructor stuff end
The question is: who calls the constructor with 0 or 1 arguments?
I discovered that if you save an object as a .mat file and try to load it, matlab will call the constructor with 0 args. Why? What initial values should I use for f1, f2, and when will they be set properly (i.e., with their old values)? Is there a way to avoid having to handle the 0/1 case explicitely?