| MATLAB® | ![]() |
As an alternative to the addpath function, use the Set Path dialog box.
addpath('directory')
addpath('dir','dir2','dir3' ...)
addpath('dir','dir2','dir3' ...'-flag')
addpath dir1 dir2 dir3 ... -flag
addpath('directory') adds the specified directory to the top (also called front) of the current MATLAB search path. Use the full pathname for directory.
addpath('dir','dir2','dir3' ...) adds all the specified directories to the top of the path. Use the full pathname for each dir.
addpath('dir','dir2','dir3' ...'-flag') adds the specified directories to either the top or bottom of the path, depending on the value of flag.
flag Argument | Result |
|---|---|
0 or begin | Add specified directories to the top of the path |
1 or end | Add specified directories to the bottom (also called end) of the path |
addpath dir1 dir2 dir3 ... -flag is the unquoted form of the syntax.
To recursively add subdirectories of your directory in addition to the directory itself, run
addpath(genpath('directory'))Use addpath statements in your startup.m file to use the modified path in future sessions. For details, see Automatically Modifying the Search Path at Startup in the MATLAB Desktop Tools and Development Environment documentation.
For the current path, viewed by running path,
MATLABPATH c:\matlab\toolbox\general c:\matlab\toolbox\ops c:\matlab\toolbox\strfun
you can add c:/matlab/mymfiles to the front of the path by running
addpath('c:/matlab/mymfiles')Verify that the files were added to the path by running
path
and MATLAB returns
MATLABPATH c:\matlab\mymfiles c:\matlab\toolbox\general c:\matlab\toolbox\ops c:\matlab\toolbox\strfun
You can also use genpath in conjunction with addpath to add subdirectories to the path. For example, to add /control and its subdirectories to the path, use
addpath(genpath(fullfile(matlabroot,'toolbox/control')))
genpath, path, pathsep, pathtool, rehash, restoredefaultpath, rmpath, savepath, startup
Search Path in the MATLAB Desktop Tools and Development Environment documentation
![]() | addParamValue (inputParser) | addpref | ![]() |

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 |