|Programming and Data Types|
Save and Load
This section covers the following topics:
Saving Data from the Workspace
To save data from your workspace, you can do any of the following:
diaryfile, and then edit the file in a text editor.
For more information: See Using the diary Command to Export Data," Saving the Current Workspace," and "Using Low-Level File I/O Functions" in the MATLAB "Development Environment" documentation
Loading Data into the Workspace
Similarly, to load new or saved data into the workspace, you can do any of the following:
For more information: See Loading a Saved Workspace and Importing Data," and "Using Low-Level File I/O Functions" in the MATLAB "Development Environment" documentation
Viewing Variables in a MAT-File
To see what variables are saved in a MAT-file, use
whos as shown here (the
.mat extension is not required).
who returns a cell array and
whos returns a structure array.
Appending to a MAT-File
To save additional variables to an existing MAT-file, use
Any variables you save that do not yet exist in the MAT-file are added to the file. Any variables you save that already exist in the MAT-file overwrite the old values.
Saving with the |
In this example, the second
save operation does not concatenate new elements to vector
A equal to
[1 2 3 4 5 6 7 8]) in the MAT-file. Instead, it replaces the 5 element vector,
A, with a 3 element vector, also retaining all other variables that were stored on the first
Save and Load on Startup or Quit
You can automatically save your variables at the end of each MATLAB session by creating a
.m file to
save the contents of your base workspace every time you quit MATLAB. Load these variables back into your workspace at the beginning of each session by creating a
.m file that uses the
load function to load variables from your MAT-file.
For more information: See the
finish function reference pages
Saving to an ASCII File
When you save matrix data to an ASCII file using
-ascii, MATLAB combines the individual matrices into one collection of numbers. Variable names are not saved. If this is not acceptable for your application, use
fprintf to store your data instead.
For more information: See Exporting ASCII Data in the MATLAB "Development Environment" documentation
|Program Control||Files and Filenames|