|
This issue came up in another thread, but it piqued my curiosity.
It seems that subfunctions in a classdef file are visible to class properties and methods, but for some reason they are not visible in the classdef Attributes block. I'm wondering if this is intentional or a bug.
EXAMPLE:
classdef myClass
properties
prop=initialize;
end
methods
function out=myfunc(obj)
out=initialize;
end
end
end
function out=initialize();%appears in myClass.m
out=true;
end
%%%%%%%%
This works fine
>> clear classes; A=myClass; A.prop, A.myfunc,
ans =
1
ans =
1
However, if I add a class Attribute block
classdef (Sealed=initialize) myClass
then instantiating the class causes an error.
>> clear classes; A=myClass;
??? Error using ==> myClass
Error: File: myClass.m Line: 1 Column: 11
Undefined function or variable 'initialize'.
This problem goes away if I relocate initialize() to its own separate M-file, but I'm wondering why this would be necessary.
|