Desktop Tools and Development Environment Previous page   Next Page

Saving the Current Workspace

The workspace is not maintained across MATLAB sessions. When you quit MATLAB, the workspace is cleared. You can save any or all of the variables in the current workspace to a MAT-file, which is a MATLAB specific binary file. You can then load the MAT-file at a later time during the current or another session to reuse the workspace variables. MAT-files use a .mat extension.

Saving All Variables

To save all of the workspace variables using the Workspace browser,

  1. From the File menu, select Save Workspace As, or click the Save button in the Workspace browser toolbar.
  1. The Save dialog box opens.

  1. Specify the location and File name. MATLAB automatically supplies the .mat extension.
  2. Click Save.
  1. The workspace variables are saved under the MAT-file name you specified.

You can also save the workspace variables from the desktop by selecting Save Workspace As from the File menu.

Saving Selected Variables

To save some but not all of the current workspace variables,

  1. Select the variable in the Workspace browser. To select multiple variables, Shift+click or Ctrl+click.
  2. Right-click and from the context menu, select Save As.
  1. The Save to MAT-File dialog box opens.

  1. Specify the location and File name. MATLAB automatically supplies the .mat extension.
  2. Click Save.
  1. The workspace variables are saved under the MAT-file name you specified.

To specify preferences for saving MAT-files, see MAT-Files.

Function Alternative

To save workspace variables, use the save function followed by the filename you want to save to. For example,

save('june10')

saves all current workspace variables to the file june10.mat.

If you don't specify a filename, the workspace is saved to matlab.mat in the current working directory. You can specify which variables to save, as well as control the format in which the data is stored, such as ASCII. For these and other forms of the function, see the reference page for save. For a related function, see genvarname. MATLAB provides additional functions for saving information--see Data Import and Export in the MATLAB Programming documentation.


Previous page  Opening the Workspace Browser Loading a Saved Workspace and Importing Data Next page

© 1994-2005 The MathWorks, Inc.