Is there exist() functionality for packages/namespaces?
조회 수: 13 (최근 30일)
이전 댓글 표시
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
채택된 답변
Ashley Trowell
2023년 10월 26일
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
추가 답변 (1개)
Walter Roberson
2023년 1월 6일
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
Walter Roberson
2023년 1월 7일
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Software Development Tools에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!