userpath - View or change default user work folder - MATLAB (original) (raw)
Main Content
View or change default user work folder
Syntax
Description
userpath([newpath](#btn2ix6-1-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.
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. If$HOME/Documents
does not exist, the function returns[]
and no valid path is set.
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.
Examples
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.
In this example, H
is the drive in whichDocuments
is located.
Confirm that the current folder is the_userpath
_ folder.
Display the search path. MATLAB returns the search path, including the folder specified byuserpath
.
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 toC:\Research_Project
.
newpath = "C:\Research_Project"; userpath(newpath)
View the effect of the change by displaying the search 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 byuserpath
. 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.
Verify that it is on the search path.
MATLABPATH
H:\Documents\MATLAB C:\Program Files\MATLAB\R2009a\toolbox\matlab\general C:\Program Files\MATLAB\R2009a\toolbox\matlab\ops ...
Clear the value.
Verify the result.
Confirm that the former userpath
folder is removed from the search 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
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 setting, located in the General Settings page of the Settings 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 theMATLABPATH
environment variable to the search path below the_userpath
_ folder at startup.
Version History
Introduced in R2008a