Construtor does not find external functions

1 vue (au cours des 30 derniers jours)
PolynomialChaos
PolynomialChaos le 23 Mar 2017
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

Réponse acceptée

Matt J
Matt J le 23 Mar 2017
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.

Plus de réponses (1)

Steven Lord
Steven Lord le 23 Mar 2017
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.

Catégories

En savoir plus sur Class Introspection and Metadata dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by