Documentation Center

  • Trial Software
  • Product Updates

addpath

Add folders to search path

Syntax

  • addpath(folderName1,...,folderNameN) example
  • addpath(folderName1,...,folderNameN,position) example

Description

example

addpath(folderName1,...,folderNameN) adds the specified folders to the top of the search path. Use addpath statements in a startup.m file to modify the search path programmatically at startup.

example

addpath(folderName1,...,folderNameN,position) adds the specified folders to the top or bottom of the search path, as specified by position.

example

addpath(___,'-frozen') additionally disables folder change detection on Windows® for folders being added, which conserves Windows change notification resources (Windows only). Type help changenotification in the Command Window for more information.

Add '-frozen' to the input arguments in any of the previous syntaxes. You can specify '-frozen' and position in either order.

example

oldpath = addpath(___) additionally returns the path prior to adding the specified folders.

Examples

expand all

Add Folder to Top of Search Path

If you do not have a folder called c:/matlab/myfiles, create the folder.

mkdir('c:/matlab/myfiles')

Add c:/matlab/myfiles to the top of the search path.

addpath('c:/matlab/myfiles')

Add Folder to End of Search Path

Add c:/matlab/myfiles to the end of the search path.

addpath('c:/matlab/myfiles','-end')

Add Folder and Its Subfolders to Search Path

Add c:/matlab/myfiles and its subfolders to the search path.

Call genpath inside of addpath to add all subfolders of c:/matlab/myfiles to the search path.

addpath(genpath('c:/matlab/myfiles'))

Add Folder to Search Path and Disable Folder Change Notification

On Windows, add the folder c:/matlab/myfiles to the top of the search path, disable folder change notification, and return the search path before adding the folder.

oldpath = addpath('c:/matlab/myfiles','-frozen');

Input Arguments

expand all

folderName1,...,folderNameN — Names of folders to add to search pathstring

Names of folders to add to the search path, specified as strings. Use the full path name for each folder. Use genpath with addpath to add all subfolders of folderName.

Example: 'c:\matlab\work'

Example: '/home/user/matlab'

Example: '/home/user/matlab','/home/user/matlab/test'

position — Position on the search path'-begin' (default) | '-end'

Position on the search path, specified as one of the following strings.

Value of position

Description

'-begin'

Add specified folders to the top of the search path.

'-end'

Add specified folders to the bottom of the search path.

Output Arguments

expand all

oldpath — Path prior to addition of foldersstring

Path prior to the addition of folders, returned as a string.

More About

expand all

Tips

  • If you use addpath within a local function, the path change persists after program control returns from the function. That is, the scope of the path change is global.

See Also

| | | |

Was this topic helpful?