Class is not found in the current folder or on the MATLAB path
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2021-9-4
编辑:Walter Roberson
2021-9-4
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!