When you open a project, MATLAB® adds the project path to the MATLAB search path and then runs or loads specified startup files. The project path and startup files help you set up the environment for your project. Similarly, when you close a project, MATLAB removes the project path from the MATLAB search path and runs specified shutdown files. Shutdown files help you clean up the environment for your project. Use shutdown files to undo the setup that occurs in startup files.
More specifically, when you open a project, MATLAB changes the current folder to the project startup folder, and runs
.p files) or loads
.mat files) any specified startup file. For more information
about configuring the startup folder, see Set Startup Folder.
You can add or remove folders from the project path. Adding a project folder to the project path ensures that all users of the project can access the files within it.
To add a folder to the project path, on the Project tab, in the Environment section, click Project Path. Click Add Folder and select the folder that you want to add. To add a folder and all of its subfolders, click Add with Subfolders.
To remove a folder from the project path, select the folder from the displayed list and click Remove.
You also can add or remove a folder from the project Files view. Right-click the folder, select Project Path, and select from the available options.
Folders on the project path appear with the project path icon in the Status column of the Files view.
When you open the project, the current working folder changes to the project startup folder. By default, the startup folder is set to the project root.
To edit the project startup folder, on the Project tab, in the Environment section, click Details. Then, in the Start up section, enter a path for the project startup folder.
To configure a file to run when you open your project, right-click the file and select Run at Startup. To configure a file to run when you close your project, right-click the file and select Run at Shutdown. The Status column displays an icon indicating whether the file runs at startup or shutdown.
To stop a file from running at startup or shutdown, right-click the file and select Remove from Startup or Remove from Shutdown.
Alternatively, go to the Project tab and click Startup Shutdown. Then, in the Manage Project Startup and Shutdown dialog box, use the Add and Remove buttons to manage the startup and shutdown file lists. The files run from the top down. If the order in which the files are run is important, use the arrow buttons to move files up or down in the list.
Startup and shutdown files are included when you commit modified files to source control. When you configure startup and shutdown files, they run for all other project users.
Startup files can have any name except
startup.m. A file named
startup.m on the MATLAB path runs when you start MATLAB. If your
startup.m file calls the project, an error
occurs because the project is not yet loaded. For more information about using
startup.m files, see Startup Options in MATLAB Startup File.
To create new startup and shutdown files programmatically, see
In Simulink®, you can specify additional project startup options. For more information, see Automate Startup Tasks (Simulink).