Marth
Marth

Reputation: 147

Matlab - Locating file on a path that's inside package

Been trying (unsucessfully) to use 'which' to locate a .m file inside a package. For example, calling "which('Company.m')", when Company.m is inside a +Contents folder.

So if my current folder is C:\Users\Documents\Contents (path added to Matlab paths), "which('Company.m')" indicates no file found, but if my current folder is C:\Users***\Documents\Contents\ +Contents, then it will know the location.

Why is this? I thought that the 'which' command recursively searches through all subdirectories? Is there anyway to retrieve the path name of 'Company.m' without having to specifically source into that folder?

Upvotes: 2

Views: 424

Answers (1)

Amro
Amro

Reputation: 124563

That should be:

which Contents.Company

If you dont know beforehand in which package it resides (or if its even in one), you could import them all:

import Contents.*
import OtherPackage.*
which -all Company

If you are still not satisfied, you could get a list of all top-level packages available, and search the methods they expose for the function you want:

 %# warning: this might take more than a few seconds
 p = meta.package.getAllPackages;
 b = cellfun(@(pkg) ismember('Company',{pkg.FunctionList.Name}), p);
 idx = find(b, 1, 'first');
 p{idx}.Name

Upvotes: 1

Related Questions