Class is not found in the current folder or on the MATLAB path
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Minh Tran
le 4 Sep 2021
Commenté : Walter Roberson
le 4 Sep 2021
Hi all,
I am beginner to object-oriented in Matlab and I am facing this very fundamental issue but have no idea how to solve it. First of all, I created a class Point2D.m and stored this class in the @Point2D folder. Then, this @Point2D folder is located in the path: C:\Users\minht\VinVEM\+Geometry\+Geo2D\@Point2D. Finally, I added the path folder: C:\Users\minht\VinVEM into Matlab.
However, whenever I create a new instance of the class Point2D, for example: p = Point2D(0,3), I will face this error:
" 'Point2D' is not found in the current folder or on the MATLAB path, but exists in:
C:\Users\minht\VinVEM\+Geometry\+Geo2D\@Point2D
Change the MATLAB current folder or add its folder to the MATLAB path. "
It is very questionable to me since I have already added its path to Matlab. Do you have any answers on how to fix this problem? Thank you very much in advance.
Best, Minh
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Sep 2021
Modifié(e) : Walter Roberson
le 4 Sep 2021
Do not add @ folders to the path: add the folder that the @ folder lives in. So add C:\Users\minht\VinVEM\+Geometry\+Geo2D to the path
Classes within a package folder (begining with + ) are not automatically added to the path just because a containing package folder is on the path. That is, if the class was in C:\Users\minht\VinVEM\+Geometry\@Point2D then you would add C:\Users\minht\VinVEM\+Geometry to the path and the Point2D class would be found in that, but with your class folder being in C:\Users\minht\VinVEM\+Geometry\+Geo2D\@Point2D then MATLAB is not going to automatically look inside C:\Users\minht\VinVEM\+Geometry\+Geo2D to see if there are any class folders. Using the + package folder syntax does not recursively add subfolders to the path.
3 commentaires
Walter Roberson
le 4 Sep 2021
Or you need to use the package qualification, Geometry.Geo2D.Point2D(0,2)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Function Creation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!