| MATLAB Function Reference | ![]() |
matlabroot
rd = matlabroot
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.
Run
matlabroot
MATLAB returns, for example,
C:\Program Files\MATLAB\R2008a
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.
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.
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.
ctfroot (in MATLAB Compiler), fullfile, partialpath, path, toolboxdir
![]() | matlabrc | matlab (UNIX) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |