matlabroot - Root directory

Syntax

matlabroot
rd = matlabroot

Description

matlabroot returns the name of the directory where the MATLAB software is installed. 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 as Directory Name

The term matlabroot also represents 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.

Using $matlabroot as a Literal

In some files, such as info.xml and classpath.txt, $matlabroot 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.

Sometimes, particularly in older code examples, the term $matlabroot or $MATLABROOT is not meant to be interpreted literally but is used to represent the value returned by the matlabroot function.

matlabroot on Macintosh Platforms

In R2008b (V7,7), running matlabroot returns

/Applications/MATLAB_R2008b.app

In prior versions, such as R2008a (V7.6), running matlabroot returns, for example

/Applications/MATLAB_R2008a

When you use GUIs on Macintosh platforms, you cannot directly view the contents of the MATLAB root directory. For more information, see Using File Browser GUIs on Macintosh Platforms to Navigate Within the MATLAB Root Directory.

Use in Compiled Code

To return the path to the executable in compiled mode, use the MATLAB® Compiler™ ctfroot function, or the MATLAB toolboxdir function. For details, see the MATLAB or MATLAB Compiler documentation.

Examples

Run

matlabroot

MATLAB returns, for example,

C:\Program Files\MATLAB\R2008b

To produce a full path to the toolbox/matlab/general directory that is correct for the platform on which it is executed, run

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

To change the current directory to the MATLAB root directory, run

cd(matlabroot)

To add the directory myfiles to the MATLAB search path, run

addpath([matlabroot '/toolbox/local/myfiles'])

See Also

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

Managing Files and Working with the Current Directory

  


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