Terminate MATLAB program
As an alternative to the quit function, use the Close box in the MATLAB® desktop.
a confirmation dialog box if the confirm that upon quitting preference
is selected, and if confirmed or if the confirmation preference is
not selected, terminates MATLAB after running
finish.m exists. Call
the MATLAB command prompt. To interrupt a MATLAB command,
see Stop Execution.
quit function does
not automatically save the workspace. To save the workspace or perform
other actions when quitting, create a
to perform those actions. For example, you can display a custom dialog
box to confirm quitting using a
the following examples for details. If an error occurs while
quit is canceled so that you can correct
finish.m file without losing your workspace.
for use in
finish.m and cancels quitting. It has
no effect anywhere else.
terminates MATLAB. Use this syntax to override
for example, if an errant
finish.m does not let
MATLAB includes two sample
Use them to help you create your own
or rename one of the files to
finish.m to use it.
finishsav.m—Saves the workspace
to a MAT-file when MATLAB quits.
finishdlg.m—Displays a dialog
box allowing you to cancel quitting; it uses
quit cancel and
contains the following code:
button = questdlg('Ready to quit?','Exit Dialog','Yes','No','No'); switch button case 'Yes', disp('Exiting MATLAB') %Save variables to matlab.mat save case 'No', quit cancel; end
If you want MATLAB to display the following confirmation dialog box after running quit, select Preferences in the Environment section on the Home tab. Then select the check box for Confirm before exiting MATLAB, and click OK.