Class is not found in the current folder or on the MATLAB path
8 views (last 30 days)
Show older comments
Minh Tran
on 4 Sep 2021
Commented: Walter Roberson
on 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 Comments
Accepted Answer
Walter Roberson
on 4 Sep 2021
Edited: Walter Roberson
on 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 Comments
Walter Roberson
on 4 Sep 2021
Or you need to use the package qualification, Geometry.Geo2D.Point2D(0,2)
More Answers (0)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!