MATLAB Function Reference | ![]() ![]() |
Save workspace variables on disk
Graphical Interface
As an alternative to the save
function, select Save Workspace As from the File menu in the MATLAB desktop, or use the Workspace browser.
Syntax
Description
save
by itself, stores all workspace variables in a binary format in the current directory in a file named matlab.mat
. Retrieve the data with load
. MAT-files are double-precision, binary, MATLAB format files. They can be created on one machine and later read by MATLAB on another machine with a different floating-point format, retaining as much accuracy and range as the different formats allow. They can also be manipulated by other programs external to MATLAB.
save filename
stores all workspace variables in the current directory in filename.mat
. To save to another directory, use the full pathname for the filename
. If filename
is the special string stdio
, the save
command sends the data as standard output.
save filename var1 var2 ...
saves only the specified workspace variables in filename.mat
. Use the *
wildcard to save only those variables that match the specified pattern. For example, save('A*')
saves all variables that start with A
.
save
saves the workspace variables in the format specified by ...
option
option
Remarks
When saving in ASCII format, consider the following:
'i'
).
load
function, all of the variables must have the same number of columns. If you are using a program other than MATLAB to read the saved data this restriction can be relaxed.
With the v4
flag, you can only save data constructs that are compatible with versions of MATLAB 4. Therefore, you cannot save structures, cell arrays, multidimensional arrays, or objects. In addition, you must use filenames that are supported by MATLAB version 4.
save('filename', ...)
is the function form of the syntax.
For more control over the format of the file, MATLAB provides other functions, as listed in See Also, below.
Algorithm
The binary formats used by save
depend on the size and type of each array. Arrays with any noninteger entries and arrays with 10,000 or fewer elements are saved in floating-point formats requiring 8 bytes per real element. Arrays with all integer entries and more than 10,000 elements are saved in the formats shown, requiring fewer bytes per element.
Element Range
Bytes per Element
0 to 255
1
0 to 65535
2
-32767 to 32767
2
-231+1 to 231-1
4
other
8
External Interfaces to MATLAB provides details on reading and writing MAT-files from external C or Fortran programs. It is important to use recommended access methods, rather than rely upon the specific MAT-file format, which is likely to change in the future.
Examples
To save all variables from the workspace in binary MAT-file, test.mat
, type
To save variables p
and q
in binary MAT-file, test.mat
, type
To save the variables vol
and temp
in ASCII format to a file named june10
, type
See Also
diary
, fprintf
, fwrite
, load
, workspace
![]() | runtime | saveas | ![]() |