which('folderName') - Find the Location of a subdirectory of a directory

4 ビュー (過去 30 日間)
Matthew
Matthew 2016 年 4 月 1 日
コメント済み: Star Strider 2016 年 4 月 1 日
Is there a simple way (better than brute force) to treat subdirectories as files and find the subdirectory which is highest on the matlab path?
i.e. if there exists a folder c:\Documents And Settings\user\My Documents\Matlab\myFolderName
whichOverload('myFolderName','dir')
%Should return c:\Documents And Settings\user\My Documents\Matlab\myFolderName
Note that parsing the path does not solve this immediately. The brute force way to do this would be something like
P = regexp(path,'[^;]+','match');
allItems = cellfun(@(x) dir(x),P,'UniformOutput',false);
matches = cellfun(@(x) ismember('myFolderName',{x.name}),allItems);
highestMatch = fullfile(P{find(matches,1)},'myFolderName');
But this is ugly and slow. . .

採用された回答

Star Strider
Star Strider 2016 年 4 月 1 日
Use the what function instead.
  2 件のコメント
Matthew
Matthew 2016 年 4 月 1 日
Thank you! That is very simple, and is exactly what I was looking for. Guess I need to polish up more on my documentation search skills!
Star Strider
Star Strider 2016 年 4 月 1 日
My pleasure!
I remember using it a while back (after a long expedition through the documentation to find it). I had to look it up too just now because I forgot its name. I just knew it was there somewhere.
I’m still discovering new functions and new applications for them, and I’ve been using MATLAB since 1994. MATLAB is a large language, and the documentation reflects that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by