matlabroot - Root directory

Syntax

matlabroot
rd = matlabroot

Description

matlabroot returns the name of the directory in which the MATLAB® software is installed. In compiled M-code, it returns the path to the executable. Use matlabroot to create a path to MATLAB and toolbox directories that does not depend on a specific platform, MATLAB version, or installation directory.

rd = matlabroot returns the name of the directory in which the MATLAB software is installed and assigns it to rd.

Remarks

matlabroot

Run

matlabroot

MATLAB returns, for example,

C:\Program Files\MATLAB\R2008a

matlabroot as Directory Name

The term matlabroot is sometimes used to represent the directory where MATLAB files are installed and should not be confused with the matlabroot function. For example, "save to matlabroot/toolbox/local" means save to the toolbox/local directory in the MATLAB root directory.

$matlabroot

Sometimes the term $matlabroot is improperly used to represent the value returned by the matlabroot function.

The reason that $matlabroot notation can be confusing is that in some files, such as info.xml and classpath.txt, the preceding $ is literal. In those files, MATLAB interprets $matlabroot as the full path to the MATLAB root directory. For example, including the line

$matlabroot/toolbox/local/myfile.jar

in classpath.txt, adds myfile.jar, which is located in the toolbox/local directory, to classpath.txt.

Examples

fullfile(matlabroot,'toolbox','matlab','general')

produces a full path to the toolbox/matlab/general directory that is correct for the platform on which it is executed.

cd(matlabroot) changes the current working directory to the MATLAB root directory.

addpath([matlabroot '/toolbox/local/myfiles']) adds the directory myfiles to the MATLAB search path.

See Also

ctfroot (in MATLAB Compiler), fullfile, partialpath, path, toolboxdir

  


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