genpath - Generate path string

Syntax

genpath
genpath directory
p = genpath('directory')

Description

genpath returns a path string formed by recursively adding all the directories below matlabroot/toolbox.

genpath directory returns a path string formed by recursively adding all the directories below directory. This path string does not include directories named private or directories that begin with the character @.

p = genpath('directory') returns the path string to variable, p.

Examples

You generate a path that includes matlabroot/toolbox/images and all directories below that with the following command:

p = genpath(fullfile(matlabroot,'toolbox','images'))

p =

matlabroot\toolbox\images;matlabroot\toolbox\images\
images;matlabroot\toolbox\images\images\ja;
matlabroot\toolbox\images\imdemos;matlabroot\
toolbox\images\imdemos\ja;

You can also use genpath in conjunction with addpath to add subdirectories to the path from the command line. The following example adds the /control directory and its subdirectories to the current path.

%  Display the current path
path

              MATLABPATH

      K:\toolbox\matlab\general
      K:\toolbox\matlab\ops
      K:\toolbox\matlab\lang
      K:\toolbox\matlab\elmat
      K:\toolbox\matlab\elfun
                :
                :
                :

%  Use GENPATH to add /control and its subdirectories
addpath(genpath('K:/toolbox/control'))


%  Display the new path
path

              MATLABPATH

      K:\toolbox\control
      K:\toolbox\control\ctrlutil
      K:\toolbox\control\control
      K:\toolbox\control\ctrlguis
      K:\toolbox\control\ctrldemos
      K:\toolbox\matlab\general
      K:\toolbox\matlab\ops
      K:\toolbox\matlab\lang
      K:\toolbox\matlab\elmat
      K:\toolbox\matlab\elfun
                :
                :
                :

See Also

addpath, path, pathdef, pathsep, pathtool, rehash, restoredefaultpath, rmpath, savepath

Search Path in the MATLAB® Desktop Tools and Development Environment documentation

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS