Documentation Center

  • Trial Software
  • Product Updates
我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

matlabroot

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.

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'])

More About

expand all

Tips

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, $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 javaclasspath.txt, adds myfile.jar, which is located in the toolbox/local folder, to the static Java® class path.

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 Navigating Within the MATLAB Root Folder on Macintosh Platforms.

See Also

| |

Was this topic helpful?