Wednesday, August 5, 2009

finish

MATLAB termination M-file

Description

When MATLAB quits, it runs a script called finish.m, if it exists and is on the MATLAB search path. This is a file that you create yourself in order to have MATLAB 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
  • Select Exit MATLAB from the desktop File menu
  • Type quit or exit at the Command Window prompt

Remarks

When using Handle Graphics in finish.m, use uiwait, waitfor, or drawnow so that figures are visible. See the reference pages for these functions for more information.

Examples

Two sample finish.m files are provided with MATLAB in toolbox/local. 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

No comments:

Post a Comment