Class is not found in the current folder or on the MATLAB path
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Minh Tran
 el 4 de Sept. de 2021
  
    
    
    
    
    Comentada: Walter Roberson
      
      
 el 4 de Sept. de 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 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 4 de Sept. de 2021
        
      Editada: Walter Roberson
      
      
 el 4 de Sept. de 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 comentarios
  Walter Roberson
      
      
 el 4 de Sept. de 2021
				Or you need to use the package qualification, Geometry.Geo2D.Point2D(0,2) 
Más respuestas (0)
Ver también
Categorías
				Más información sobre Function Creation en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

