|On this page…|
To exit MATLAB® at any time, do one of the following:
Click the Close box in the MATLAB desktop.
Click on the left side of the MATLAB desktop title bar and select Close.
MATLAB closes after:
Prompting you to confirm exiting, if that preference is specified (see Confirm Exiting MATLAB.)
Prompting you to save any unsaved files
Running the finish.m script, if it exists in the current folder or on the search path (see Running a Script When Exiting MATLAB .
For information about abnormal termination, see:
To set a preference that displays a confirmation dialog box when you exit MATLAB:
On the Home tab, in the Environment section, click Preferences.
Select MATLAB > General > Confirmation Dialogs.
Select the Confirm before exiting MATLAB check box and click OK.
MATLAB then displays the following dialog box when you exit.
For more information, see Confirmation Dialogs Preferences.
You can also display your own exit confirmation dialog box using a finish.m script, as described in the following section.
When MATLAB exits, it runs the script finish.m, if finish.m exists in the current folder or anywhere on the search path. You create the file finish.m. It contains statements to run when MATLAB terminates, such as saving the workspace or displaying a confirmation dialog box. There are two sample files in matlabroot/toolbox/local that you can use as the basis for your own finish.m file:
finishsav.m — Includes a save function so the workspace is saved to a MAT-file when MATLAB quits.
finishdlg.m — Displays a confirmation dialog box that allows you to cancel quitting.
For more information, see the finish reference page.