MATLAB: Define shared subfunctions inside a classdef *.m file

classclassdef method private subfunctionmatlab oopoop

I want to define a relatively small class (small enough that it makes sense to do everything inside of one file). I want to reuse a common subfunction between several methods, and having this subfunction inside of the classdef would make it cleaner, easily portable and automatically private. However, I have not been able to do so. Is there any way to accomplish it?
>> d = dummy;
>>??? Undefined function or variable 'my_pi'.
>>
>>Error in ==> dummy>dummy.dummy at 10
>> obj.dummy = my_pi();
dummy.m:
classdef dummy
properties
value;
end
methods
function y = my_pi()
y = 3.141592;
end
function obj = dummy()
obj.dummy = my_pi();
end
end
end

Best Answer

You can define subfunctions in the same file after the definition of the class, ie
classdef dummy
...
...
end % classdef
function out = subfun1( in )
...
end
/ per