Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

matlabroot - Root folder

Syntax

matlabroot
mr = matlabroot

Description

matlabroot returns the name of the folder where the MATLAB software is installed. Use matlabroot to create a path to MATLAB and toolbox folders that does not depend on a specific platform, MATLAB version, or installation location.

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

Remarks

matlabroot as Folder Name

The term matlabroot also refers to the folder where MATLAB files are installed. For example, "save to matlabroot/toolbox/local" means save to the toolbox/local folder in the MATLAB root folder.

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 folder. For example, including the line

$matlabroot/toolbox/local/myfile.jar

in classpath.txt, adds myfile.jar, which is located in the toolbox/local folder, 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) and more recent versions, running matlabroot on Apple Macintosh platforms returns

/Applications/MATLAB_R2008b.app

In versions prior to R2008b (V7.7), such as R2008a (V7.6), running matlabroot on Macintosh platforms returns, for example

/Applications/MATLAB_R2008a

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

Use in Compiled Mode

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

Get the location where MATLAB is installed:

matlabroot

MATLAB returns:

C:\Program Files\MATLAB\R2009a

Produce a full path to the toolbox/matlab/general folder that is correct for the platform on which it is executed:

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

Change the current folder to the MATLAB root folder:

cd(matlabroot)

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

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

See Also

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

Managing Files in MATLAB

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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