|MATLAB Function Reference|
Save workspace variables on disk
As an alternative to the
save function, select Save Workspace As from the File menu in the MATLAB desktop, or use the Workspace browser.
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.
stores all workspace variables in the current directory in
filename.mat. To save to another directory, use the full pathname for the
filename is the special string
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
save saves the workspace variables in the format specified by
||Result: How Data is Stored
||The specified existed MAT-file, appended to the end
||8-digit ASCII format
||16-digit ASCII format
||delimits with tabs
||16-digit ASCII format, tab delimited
||Binary MAT-file form (default)
||A format that MATLAB version 4 can open
When saving in ASCII format, consider the following:
loadfunction, 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.
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.
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.
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.
Bytes per Element
0 to 255
0 to 65535
-32767 to 32767
-231+1 to 231-1
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.
To save all variables from the workspace in binary MAT-file,
To save variables
q in binary MAT-file,
To save the variables
temp in ASCII format to a file named