MATLAB Startup Folder

MATLAB® sets the current folder when you start MATLAB to the Initial working folder value in General Preferences. To identify the current folder, type pwd at the command line. For convenience, make the initial working folder a folder that you frequently use.

If the initial working folder is set to Location based on MATLAB startup rules, MATLAB uses the default values described in the following topics.

    Note:   If a startup.m file changes the current folder, this value overrides the initial working folder value. Do not add cd statements to startup.m.

Default Folder on Windows Platforms

How You Start MATLABStartup Folder

Double-click the MATLAB shortcut on your Windows® desktop

The startup folder is set to the userpath value, whose default value is Documents\MATLAB. The userpath folder is automatically added to the search path. If MATLAB does not find a valid userpath value, the startup folder is C:\Windows\System32.

Double-click a file type associated with MATLAB

The folder in which the file resides is the startup folder. The userpath folder is automatically added to the search path.

In a DOS window

The folder in which you ran the matlab command is the startup folder. The userpath folder is automatically added to the search path.

Default Folder on Mac Platforms

How You Start MATLABStartup Folder

Double-click the MATLAB application

The startup folder is the value returned when you enter userpath, which by default is userhome/Documents/MATLAB. MATLAB automatically adds the userpath folder to the top of its search path upon startup. To specify a different folder for userpath, and for other options, use the userpath function.

You can specify that the userpath be the startup folder by setting the value of the environment variable MATLAB_USE_USERWORK to 1.

Start MATLAB in a shell

The startup folder is the MATLAB installation folder.

Default Folder on Linux Platforms

On Linux® platforms, the default startup folder is the folder from which you started MATLAB.

To specify the userpath as the startup folder, set the value of the environment variable MATLAB_USE_USERWORK to 1 before startup. By default, userpath is userhome/Documents/MATLAB, and MATLAB automatically adds the userpath folder to the top of the search path upon startup. To specify a different folder for userpath, and for other options, use the MATLAB userpath function.

userpath as Initial Working Folder

Using userpath as the startup folder offers these benefits:

  • You can store the MATLAB files you work with in one, appropriately named location, such as Documents/MATLAB.

  • Your MATLAB files are readily available upon startup, because the current folder is always the same.

  • You can always run your files because MATLAB automatically adds the userpath folder to the top of the search path.

  • The first time you run a new version of MATLAB, MATLAB automatically creates the userpath folder if it does not exist.

  • When you upgrade to a newer version of MATLAB, MATLAB automatically continues to use the same startup folder and your existing files.

  • The default userpath utilizes the benefits provided by the standard location in the Windows and Macintosh environments for storing personal files. Files in the Documents/MATLAB folder are available to you when you use other machines. Because each user has their own Documents/MATLAB folder, other users, even those using your machine, cannot access files in your Documents/MATLAB folder.

Changing the Startup Folder

To set the initial working folder, use the General Preferences panel. On the Home tab, in the Environment section, click Preferences. Select MATLAB > General. Choose an option for the Initial working folder.

See Also

|

Related Examples

More About

Was this topic helpful?