| MATLAB® | ![]() |
| On this page… |
|---|
Ways to Quit the MATLAB® Program Confirm Quitting the MATLAB® Program |
To quit the MATLAB® program at any time, do one of the following:
Click the Close box
in the MATLAB desktop.
Select Exit MATLAB from the desktop File menu.
Type quit at the Command Window prompt.
MATLAB closes after
Prompting you to confirm quitting, if that preference is specified (see Confirm Quitting the MATLAB® Program)
Prompting you to save any unsaved files
Running the finish.m script, if it exists in the current directory or on the search path (see Running a Script When Quitting the MATLAB® Program)
To set a preference that displays a confirmation dialog box when you quit MATLAB, select File > Preferences > General > Confirmation Dialogs, select the Confirm before quitting check box, and click OK. MATLAB then displays the following dialog box when you quit.

For more information, see Confirmation Dialogs Preferences.
You can also display your own quitting confirmation dialog box using a finish.m script, as described in the following section.
When MATLAB quits, it runs the script finish.m, if finish.m exists in the current directory or anywhere on the search path. You create the file finish.m. It contains statements to run when MATLAB terminates, such as saving the workspace or displaying a confirmation dialog box. There are two sample files in matlabroot/toolbox/local that you can use as the basis for your own finish.m file:
finishsav.m — Includes a save function so the workspace is saved to a MAT-file when MATLAB quits.
finishdlg.m — Displays a confirmation dialog box that allows you to cancel quitting.
For more information, see the finish reference page.
In the event MATLAB experiences a segmentation violation (segv) or other serious problem, the MATLAB System Error dialog box opens to notify you about the problem. When this occurs, the internal state of MATLAB is unreliable and not suitable for further use. You should exit as soon as possible and then restart. However, you might want to first try to save your work in progress.
To exit and restart without trying to save your work, follow these steps:
If you want to view the stack trace for the problem, click Details.
Click Close to terminate MATLAB.
Restart MATLAB. If the Error Log Reporter dialog box opens, send a report to The MathWorks.
To try to save your work in progress before exiting and restarting MATLAB, follow these steps:
If you want to view the stack trace for the problem, click Details.
Click Attempt to Continue. MATLAB tries to return to the Command Window or tool you were using.
The Command Window displays the message Please exit and restart MATLAB to the left of the prompt, which reminds you to discontinue use.
From the Command Window or tool, try to save the workspace and unsaved files.
Exit MATLAB immediately after saving because any further usage would be unreliable.
Restart MATLAB. If the Error Log Reporter dialog box opens, send a report to The MathWorks.
Upon startup, if MATLAB detects an error log generated by a serious problem during the previous session, an Error Log Reporter prompts you to e-mail the log to The MathWorks for analysis. The error log contains the stack trace and information about the MATLAB configuration. If the problem occurs repeatedly, make note of what seems to cause it, look for information about it in the MathWorks Bug Reports database, and if the problem is reproducible, please submit a Service Request via http://www.mathworks.com/support/contact_us/ts/help_request_1.html.
E-Mailing Error Log Reports. There are some situations where the Error Log Reporter will not open, for example, when you start MATLAB with a -r option or run in deployed mode. It also will not open if you selected the option to never send error reports the last time the Error Log Reporter opened. If you experience abnormal termination but do not see the Error Log Reporter on subsequent startups, you can instead e-mail the reports.
Send e-mail to segv@mathworks.com with this file attached: C:\Temp\matlab_crash_dump.####. After you send the log file, delete it or move it to another location. If you do not delete the log file, the Error Log Reporter can detect it on the next startup and prompt you to send it, even though you already e-mailed it.
If MATLAB terminates unexpectedly, you might lose information. After you start MATLAB again, you can try these suggestions to recover some of the information.
Use the Command History or the file on which it is based, history.m, to run statements from the previous session. You might be able to approximately recreate data as it was prior to the termination. For more information, see Overview of the Command History Window.
If you used the diary function or -logfile startup option for the session in which MATLAB terminated unexpectedly, you might be able to recover output.
If you saved the workspace to a MAT-file during the session, you can recover it by loading the MAT-file. For more information, see Loading a Saved Workspace and Importing Data, and Saving the Current Workspace.
If you were editing a file in the Editor when MATLAB terminated unexpectedly, and you had the autosave preference enabled, you should be able to recover changes you made to files you had not saved.
If you were in a Simulink® session when a segmentation violation occurred, and you have the Simulink Autosave Options preference selected, note that the last autosave file for the model reflects the state of the autosave data prior to the segmentation violation. Because Simulink models might be corrupted by a segmentation violation, a model is not autosaved after a segmentation violation occurs.
Some of the above suggestions refer to actions you might have needed to take during the session when MATLAB terminated. If you did not take those actions, consider regularly performing them to help you recover from any future abnormal terminations you might experience.
![]() | Other Startup Topics | Desktop | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |