필터 지우기
필터 지우기

genpath related question, replacing genpath

조회 수: 3 (최근 30일)
MiauMiau
MiauMiau 2014년 6월 5일
답변: Geoff Hayes 2014년 6월 5일
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