genpath related question, replacing genpath

3 次查看(过去 30 天)
I have two questions regarding genpath:
(1) When I use genpath as follows:
p = genpath('/Users/myname')
I get the following:
/Users/myname/:/Users/myname/.Trash:/Users/myname/.Trash/Recovered files:/Users/myname/.Trash/Recovered files #1:/Users/myname ...
..what is that even supposed to mean? why am I not getting a string of the subfolders?
(2) In the following: addpath(genpath('/Users/myname')) I want to replace the genpath (it does not work propertly with a certain program). How can I do that?
Thanks

回答(1 个)

Geoff Hayes
Geoff Hayes 2014-6-5
According to the documentation on genpath (type help genpath or doc genpath in the Command Window for details)
P = genpath(D) returns a path string starting in D, plus, recursively,
all the subdirectories of D, including empty subdirectories.
So your above result, /Users/myname/:/Users/myname/.Trash:/Users/myname/.Trash/Rec…, includes the path string starting in /Users/myname/, and all subdirectories of * /Users/myname/ with each subdirectory separated by a colon.
As for addpath, in the Command Window type help add path or doc add path for details. It includes several examples
Examples
addpath c:\matlab\work
addpath /home/user/matlab
addpath /home/user/matlab:/home/user/matlab/test:
addpath /home/user/matlab /home/user/matlab/test
I tried addpath(genpath('/Users/geoff/Dev/test')) and it worked fine, adding this directory and all subdirectories as expected. If you are finding that your statement addpath(genpath('/Users/myname')) does not work, then simply edit out the directories from genpath that are invalid:
pathString =genpath('/Users/myname');
% do your edits on pathString
addpath(pathStringEdited);

类别

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