| MATLAB Function Reference | Search  Help Desk |
| save | See Also |
Save workspace variables on disk
Syntax
save save filename save filename variables save filename options save filename variables options
Description
save
stores all workspace variables in a binary format in the file named matlab.mat. The data can be retrieved with load.
save filename
stores all workspace variables in filename.mat instead of the default matlab.mat. If filename is the special string stdio, the save command sends the data as standard output.
save filename variables
saves only the workspace variables you list after the filename. For example, save myfile x y z saves only the variables x, y, and z to myfile.mat.
The function form of the syntax, save('filename'), is also permitted. So, for example, to save variables x and y to the filename myfile, use
save ('myfile', 'x', 'y')
These forms of the save command use options:
save filename options
save filename variables options
Valid option combinations are shown in the table below.Limitations
Saving complex data with the-ascii option causes the imaginary part of the data to be lost, as MATLAB cannot load nonnumeric data ('i').
Remarks
Thesave and load commands retrieve and store MATLAB variables on disk. They can also import and export numeric matrices as ASCII data files.
MAT-files are double-precision binary MATLAB format files created by the save command and readable by the load command. 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 disparate formats allow. They can also be manipulated by other programs, external to MATLAB.
Notes on Options
Variables saved in ASCII format merge into a single variable that takes the name of the ASCII file. Therefore, loading the filefilename shown above results in a single workspace variable named filename. Use the colon operator to access individual variables.
If you save MATLAB version 5 data with the -V4 option, you must use a filename that MATLAB version 4 supports. In addition, you can only save data constructs that are compatible with MATLAB version 4; therefore, you cannot save structures, cell arrays, multidimensional arrays, or objects.
Algorithm
The binary formats used bysave 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 eight 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 |
See Also
fprintf, fwrite, load, quit