필터 지우기
필터 지우기

find the absolute path of a package

조회 수: 21 (최근 30일)
Daniel
Daniel 2014년 12월 3일
댓글: Daniel 2014년 12월 3일
Hi!
is there an obvious way to find out the absolute path of a package? I mean, if I define a package directory some where in my file system, say,
mkdir <mypath>/+myPackage
and the add its location to the path
addpath <mypath>
then myPackage is active and I can invoke functions from there. But how can I ask the system where this package resides? I mean
which myPackage
does not work. I could make a which to a function inside the myPackage, yes, but I have hundreds of packages, and packages inside packages, and they don't contain the same functions.
any idea? Daniel

채택된 답변

Guillaume
Guillaume 2014년 12월 3일
편집: Guillaume 2014년 12월 3일
It's the what function you want:
s = what('event'); %there may be several packages with the same name. s may be an array of structs
s.path
You can also get a lot of information from the meta.package classes (but not the path unfortunately):
mpack = meta.package.fromName('event')
allpackages = meta.package.getAllPackages
  댓글 수: 1
Daniel
Daniel 2014년 12월 3일
exactly! Thanks, Guillaume! The output is a little confusing (I get an arrays of structs, one for the absolute path of the package and one for the relative path!), but I'm closer to goal now. This meta.xxx objects are really useful, and I keep forgetting they exist!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 12월 3일
If you know the name of one of the m-files in the package, then you can do this:
% Determine folder where someFunction.m lives.
folder = fileparts(which('someFunction.m'));
  댓글 수: 1
Daniel
Daniel 2014년 12월 3일
The problem is that I have lots of packages, and cannot predict in advance the name of a function garanteed to be inside a given package.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by