Construtor does not find external functions

1 Ansicht (letzte 30 Tage)
PolynomialChaos
PolynomialChaos am 23 Mär. 2017
Beantwortet: Steven Lord am 23 Mär. 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

Akzeptierte Antwort

Matt J
Matt J am 23 Mär. 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.

Weitere Antworten (1)

Steven Lord
Steven Lord am 23 Mär. 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.

Kategorien

Mehr zu Class Introspection and Metadata finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by