Class is not found in the current folder or on the MATLAB path
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Minh Tran
il 4 Set 2021
Commentato: Walter Roberson
il 4 Set 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 Commenti
Risposta accettata
Walter Roberson
il 4 Set 2021
Modificato: Walter Roberson
il 4 Set 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 Commenti
Walter Roberson
il 4 Set 2021
Or you need to use the package qualification, Geometry.Geo2D.Point2D(0,2)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Function Creation 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!