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!