| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
When the MATLAB program quits, it runs a script called finish.m, if the script exists and is on the search path MATLAB uses or in the current directory. This is a file you create yourself that instructs MATLAB to perform any final tasks just prior to terminating. For example, you might want to save the data in your workspace to a MAT-file before MATLAB exits.
finish.m is invoked whenever you do one of the following:
Click the Close box
in the MATLAB desktop on Microsoft Windows platforms
or the equivalent on UNIX[1]
platforms
Select Exit MATLAB from the desktop File menu
Type quit or exit at the Command Window prompt
When using Handle Graphics features in finish.m, use uiwait, waitfor, or drawnow so that figures are visible. See the reference pages for these functions for more information.
Two sample finish.m files are provided with MATLAB in matlabroot/toolbox/local. Use them to help you create your own finish.m, or rename one of the files to finish.m and add it to the path 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 and saves the workspace. See also the Confirmation Dialogs Preferences and the option for exiting MATLAB.
Quitting the MATLAB Program in the MATLAB Desktop Tools and Development Environment documentation
[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
![]() | findstr | fitsinfo | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |