Development Environment | ![]() ![]() |
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.
Saving All Variables. To save all of the workspace variables using the Workspace browser:
The workspace variables are saved under the MAT-file name you specified.
You can also save the workspace variables from the Command Window by selecting Save Workspace As from the File menu.
Saving Selected Variables. To save some but not all of the current workspace variables:
The workspace variables are saved under the MAT-file name you specified.
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
. MATLAB provides additional functions for saving information - see Chapter 6, Importing and Exporting Data.
![]() | Viewing the Current Workspace | Loading a Saved Workspace | ![]() |