Is there exist() functionality for packages/namespaces?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Chris
el 6 de En. de 2023
Respondida: Ashley Trowell
el 26 de Oct. de 2023
Create a package and put it somewhere in Matlab's path. If you know the parent directory, you could use exist('/path/+package'), but you don't need to know the path to use the package, so that's silly.
The current best solution I have is to try/catch calling a function in the package.
0 comentarios
Respuesta aceptada
Ashley Trowell
el 26 de Oct. de 2023
There is, but it is hidden. Mathworks doesn't encourage packages and namespaces.
Reference: meta.package.fromname
Create this lambda function:
packageExists = @(pkgName) ~isempty(meta.package.fromName(pkgName));
Then run
pkgExist = packageExists('myPkg');
A nice utility is here that just adds the functionality the the exist function, which is what Mathworks should do.
0 comentarios
Más respuestas (1)
Walter Roberson
el 6 de En. de 2023
You can exist() a function inside the package
exist('matlab.internal.lang.capability.Capability')
which matlab.internal.lang.capability.Capability
You can also which the + form of a function (but not the package itself)
which +matlab/+internal/+lang/+capability/Capability
which +matlab/+internal/+lang/+capability
5 comentarios
Walter Roberson
el 7 de En. de 2023
Class methods can be found using which, but sometimes they will not be located unless the class has been loaded at least once in this session (since the last clear classes)
Ver también
Categorías
Más información sobre Software Development Tools 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!