Main Content

startup

User-defined startup script for MATLAB

Syntax

Description

startup executes user-specified commands when starting MATLAB®. MATLAB executes any file on the search path named startup that has an executable file extension. Examples of an executable file extension are .m, .mlx, and .mlapp.

Create a startup.m file in the userpath folder, which is on the MATLAB search path. Add commands you want executed at startup. For example, your code might include physical constants, defaults for graphics properties, engineering conversion factors, or anything else you want predefined in your workspace.

example

Examples

collapse all

Open startup.m in your userpath folder.

edit(fullfile(userpath,'startup.m'))

Set the default colormap to autumn. Enter this statement into the file.

set(0, 'DefaultFigureColormap', autumn(64))

Save and close the file.

Restart MATLAB and display a plot.

surf(peaks)

The default colormap value is autumn.

Restore the default colormap value. Remove the set statement for DefaultFigureColormap.

edit(fullfile(userpath,'startup.m'))

Save and close the file. The next time you start MATLAB, the default colormap value is the MATLAB default.

Locate the startup.m file.

which startup
delete(fullfile(userpath,'startup.m'))

Tips

  • To specify the current folder in MATLAB when it starts, set the Initial working folder preference located in the General Preferences page of the Preferences.

Algorithms

At startup, MATLAB automatically executes the matlabrc function and, if it exists on the MATLAB search path, startup. The matlabrc file, which is in the matlabroot/toolbox/local folder, is reserved for use by MathWorks® and by system administrators on multiuser systems.

Version History

Introduced before R2006a