Is it acceptable to write sub-functions in a class definition file outside of the CLASSDEF/END block in MATLAB 7.7 (R2008b)?

5 views (last 30 days)
I have created a class definition file as follows:
classdef mytry
properties
a;
end
methods
function obj = mytry(s)
obj.a = s;
mydisp(obj)
end
end
end
function mydisp(obj)
obj.a
end
Please note that I have saved the function 'mydisp' in the same file 'mytry.m' which contains the class definition.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Jan 2010
This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
Writing sub-functions outside the CLASSDEF/END block is an acceptable and supported way of writing functions.
Sub-functions in CLASSDEF files work like sub-functions in FUNCTION files. They can be called from anywhere in the same file but are not visible outside of the file in which they reside. Sub-functions in CLASSDEF files are useful for utility functions that are needed only within that one file. These functions may take or return parameters that are instances of the class but, it is not necessary that they follow this behavior.

More Answers (0)

Products


Release

R2008b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!