Main Content

userpath

View or change default user work folder

Description

userpath returns a user-specific folder that MATLAB® adds to the search path at startup. The function returns the folder as a character vector. For more information about the search path, see What Is the MATLAB Search Path?

For additional information on configuring MATLAB startup options, see Startup Options in MATLAB Startup File.

example

userpath(newpath) sets the user-specific folder on the search path to newpath. The specified folder appears on the search path immediately and at startup in future sessions. MATLAB removes the folder previously specified by userpath from the search path.

example

userpath("reset") sets the user-specific folder on the search path to the default for your platform. The default userpath folder depends on your platform:

  • Windows® platforms — %USERPROFILE%\Documents\MATLAB

  • Mac platforms — $home/Documents/MATLAB

  • Linux® platforms — $home/Documents/MATLAB if $home/Documents exists

MATLAB immediately adds the default folder to the search path and also adds it to the search path at startup in future sessions. On Windows and Mac platforms, the default folder is created if it does not exist. On Linux, the default folder is not created if it does not exist.

userpath("clear") removes the user-specific folder from the search path immediately and for future MATLAB sessions.

example

Examples

collapse all

This example assumes the userpath folder is set to the default value Documents\MATLAB on the Windows platform. Start MATLAB and display the current folder.

pwd
H:\Documents\MATLAB

In this example, H is the drive in which Documents is located.

Confirm that the current folder is the userpath folder.

userpath
H:\Documents\MATLAB

Display the search path. MATLAB returns the search path, including the folder specified by userpath.

path
MATLABPATH

	H:\Documents\MATLAB
	C:\Program Files\MATLAB\R2009a\toolbox\matlab\general
	C:\Program Files\MATLAB\R2009a\toolbox\matlab\ops
...

Assume the userpath folder is set to the default value on the Windows platform, Documents\MATLAB.

Change the value from the default to C:\Research_Project.

newpath = "C:\Research_Project";
userpath(newpath)

View the effect of the change by displaying the search path.

path
MATLABPATH

	C:\Research_Project
	C:\Program Files\MATLAB\R2009a\toolbox\matlab\general
	C:\Program Files\MATLAB\R2009a\toolbox\matlab\ops
...

MATLAB displays the search path, including the folder specified by userpath. MATLAB automatically removes the previous value of the userpath folder, H:\Documents\MATLAB, from the search path when you assign a new folder using userpath.

Assume that the userpath folder is set to the default value, but you do not want it to be added to the search path at startup.

Confirm that the default is set.

userpath
H:\Documents\MATLAB

Verify that it is on the search path.

path
MATLABPATH

H:\Documents\MATLAB
C:\Program Files\MATLAB\R2009a\toolbox\matlab\general
C:\Program Files\MATLAB\R2009a\toolbox\matlab\ops
...

Clear the value.

userpath("clear")

Verify the result.

userpath
ans =
     ''

Confirm that the former userpath folder is removed from the search path.

path
MATLABPATH

C:\Program Files\MATLAB\R2009a\toolbox\matlab\general
C:\Program Files\MATLAB\R2009a\toolbox\matlab\ops
...

Note

If you use userpath("clear"), the startup folder will not necessarily be on the search path. This situation can also occur if you remove the userpath folder from the search path and save the changes.

Input Arguments

collapse all

New value for the userpath folder, specified as a string scalar or character vector. newpath must be an absolute path.

Example: "C:\myFolder"

Limitations

  • In MATLAB Online™, you can only view the userpath folder. Changing the folder is not supported.

Tips

  • To specify the startup folder, set the Initial working folder preference, located in the General Preferences page of the Preferences window. For more information about using userpath as the initial working folder, see userpath as Initial Working Folder.

  • The MATLABPATH environment variable can contain a list of folders to be added to the search path. MATLAB adds the folders specified in the MATLABPATH environment variable to the search path below the userpath folder at startup.

Version History

Introduced in R2008a