Construtor does not find external functions
1 次查看(过去 30 天)
显示 更早的评论
The constructor of a Class does not find a function in an .m file as soon as I move the function .m file to the Class folder, where the Class .m file is. It works as long as the function .m file is in the main folder. What do I have to do so that the constructor finds the fctn in the Class folder?
The error message is: Undefined function 'fctn' for input arguments of type 'double'.
classdef Data
properties
propA;
end
methods
function obj = Data (attrA)
[obj.propA] = fctn(attrA);
end
end
end
0 个评论
采纳的回答
Matt J
2017-3-23
You could make a private/ folder in the class folder and put your function in there. You could also place the function in the classdef file as a subfunction.
0 个评论
更多回答(1 个)
Steven Lord
2017-3-23
If you want fctn to be a method of class Data that is defined outside the classdef file, you need to define it as a method in the class file itself, then write the implementation in the separate file. See this section of the documentation for more information.
If you want fctn to be a function, not a method, that's accessible to the class but you don't want it to be visible to any other function or class you'll probably want to make it a private function. See the section titled "Access to Functions Defined in Private Folders" in this documentation page. Alternately you could make it a class-related function in the file itself.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Class Introspection and Metadata 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!