Searching for a directory in matlab Path

66 Ansichten (letzte 30 Tage)
Deepak
Deepak am 22 Aug. 2011
Hi, I want to find out if a particular directory name exists in the matlab path. This I can do easily with exist('dirname','dir') If the directory now exists, then I wish to find its complete path from the Matlab PathList. Could someone help me out with this.
Thanks.

Antworten (2)

Fangjun Jiang
Fangjun Jiang am 22 Aug. 2011
I don't fully understand how exist('dirname','dir') works. If you need to find out the full path, I recommend the following code which tries to find the folder 'simulink'.
use regexpi() to replace strfind() if want to ignore the case, but then also need to take care of the backlash '\'. Maybe should just use
Ind=strfind(lower(PathStr),lower([filesep,'dirname']))
PathStr=regexp(path,pathsep,'split');
Ind=strfind(PathStr,[filesep,'simulink']);
Ind=cellfun('isempty',Ind);
FoundPath=PathStr(~Ind)

Subhadra Mahanti
Subhadra Mahanti am 4 Feb. 2016
If exist(myDir,'dir')==7 I usually go to the MATLAB root and do a system find, but remember this can return several values based on all the directories with the name myDir on the path
cd(matlabroot)
!find . -name myDir
Another way to run system commands in MATLAB is
[status,cmdout] = system(cmd,'echo') % where cmd='find . -name myDir &'

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by