At any time, do one of the following:
Click the close button on the MATLAB® desktop.
Click on the left side of the desktop title bar
and select Close.
Type quit
or exit
at the command
prompt.
MATLAB closes after:
Prompting you to confirm exiting, if that preference is specified.
Prompting you to save any unsaved files
Running a script when
exiting, if the finish.m
script exists in the
current folder or on the search path.
To set a preference that displays a confirmation dialog box when you exit:
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.
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 the file
exists in the current folder or anywhere on the search path. You create the script
containing statements such as saving the workspace or displaying a confirmation
dialog box. For more information, see finish
.
There are two sample files in
that you
can use as the basis for your own matlabroot
/toolbox/localfinish.m
file:
finishsav.m
— Includes a save
function so the workspace is saved to a MAT-file.
finishdlg.m
— Displays a confirmation dialog box
that allows you to cancel quitting.