Are .m files in a subfolder of a class folder considered methods of that class?
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 18 Giu 2019
Modificato: per isakson
il 19 Giu 2019
I am creating a class using the class folder approach. I understand from the MATLAB documentation that any .m file in my class folder will be treated as a method of the class.
I would like to create a subfolder within my class folder. Will .m files within this subfolder also be treated as methods of the class?
Ex. @myClass > subfolder > myMethod.m
Risposta accettata
MathWorks Support Team
il 19 Giu 2019
Files in a subfolder of a class folder are not considered methods of the class.
Please refer to the following example:
@myClass > myClass.m:
classdef myClass
methods
function classObj = myClass()
classObj.method1()
classObj.method2()
end
end
end
@myClass > method1.m:
function method1(classObj)
disp('method in class folder')
end
@myClass > subfolder > method2.m:
function method2(classObj)
disp('method in subfolder')
end
-----
>> m = myClass
method in class folder
Unrecognized method, property or field 'method2' for class 'myClass'.
Error in myClass (line 5)
classobj.method2()
As you can see, 'method1' is part of the class, but 'method2', which is in a subfolder of '@myClass', is not treated as a method of the class.
For more details about using class folders in MATLAB, please see the following documentation page:
1 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Class File Organization in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!