Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

userpath

View or change default user work folder

Syntax

Description

example

userpath returns the first folder on the search path, specified as a character vector. MATLAB® adds the folder specified by userpath to the search path at startup.

example

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

    Note:   By default, the startup folder is the userpath folder when you start MATLAB by double-clicking the shortcut on Windows® platforms, or by double-clicking the application on Mac platforms. If you change the userpath folder, 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.

userpath('reset') sets the first 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 top of 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 first 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. The folder specified by userpath is at the top.

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, with the folder specified by userpath at the top. 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 at the top of 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. newpath must be an absolute path.

Example: 'C:\myFolder'

More About

collapse all

Tips

  • To specify the startup folder, set the Initial working folder preference, described in General Preferences.

  • You can automatically add subfolders to the top of the search path at startup by specifying the path for the subfolders via the MATLABPATH environment variable.

See Also

| | | |

Introduced in R2008a

Was this topic helpful?