| MATLAB Function Reference | Search  Help Desk |
| quit | Examples See Also |
Syntax
quit quit cancel quit force
Description
quit
terminates MATLAB after running finish.m, if finish.m exists. The workspace is not automatically saved by quit. To save the workspace or perform other actions when quitting, create a finish.m file to perform those actions. If an error occurs while finish.m is running, quit is canceled so that you can correct your finish.m file without losing your workspace.
quit cancel
is for use in finish.m and cancels quitting. It has no effect anywhere else.
quit force
bypasses finish.m and terminates MATLAB. Use this to override finish.m, for example, if an errant finish.m will not let you quit.
Remarks
When using Handle Graphics infinish.m, use uiwait, waitfor, or drawnow so that figures are visible. See the reference pages for these commands for more information.
Examples
Two samplefinish.m files are included with MATLAB. Use them to help you create your own finish.m, 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 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
See Also
save, startup