Main Content

userpath

View or change default user work folder

Description

example

userpath returns a user-specific folder that MATLAB® adds to the search path at startup, specified as a character vector.

example

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

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

  • 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.

example

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

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 at 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 on 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 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 character vector or string scalar. newpath must be an absolute path.

Example: 'C:\myFolder'

Data Types: char | string

Limitations

  • In MATLAB Online™, you only can view the folder specified by userpath. 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.

  • 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