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

10 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by