This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

finish

User-defined termination script for MATLAB

Syntax

finish

Description

example

finish executes user-specified commands when exiting. MATLAB® calls the finish.m script, if defined, whenever you do one of the following.

  • Click the close button on the MATLAB desktop on Microsoft® Windows® platforms or the equivalent on UNIX® platforms.

  • Type quit or exit at the command prompt.

If an error occurs in the finish script, then quit is canceled so that you can correct your finish.m file without losing your workspace.

Examples

collapse all

Use the MATLAB sample file finishsav.m to save the workspace to a MAT-file when MATLAB quits.

To view the contents or edit the file, open the finishsav.m file in the editor.

edit(fullfile(matlabroot,'toolbox','local','finishsav.m'));

Copy the file to the search path and rename it to finish.m.

copyfile(fullfile(matlabroot,'toolbox','local','finishsav.m'),fullfile(userpath,'finish.m'))

Use the MATLAB sample file finishdlg.m to display a custom dialog box allowing you to cancel when MATLAB quits.

To view the contents or edit the file, open the finishdlg.m file in the editor.

edit(fullfile(matlabroot,'toolbox','local','finishsav.m'));

Copy the file to the search path and rename it to finish.m.

copyfile(fullfile(matlabroot,'toolbox','local','finishdlg.m'),fullfile(userpath,'finish.m'))

Note

To display this confirmation dialog box, set the Confirm before exiting MATLAB option in General Preferences.

Tips

  • When using graphics objects in finish.m, call uiwait, waitfor, or drawnow so that figures are visible.

See Also

| |

Introduced before R2006a