Thursday, August 13, 2009

genpath


Generate a 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. Empty directories are not included.

genpath directory returns a path string formed by recursively adding all the directories below directory. Empty directories are not included.

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
    :
    :
    :



No comments:

Post a Comment