MATLAB Function Reference
  Go to function:
    Search    Help Desk 
save    See Also

Save workspace variables on disk

Syntax

Description

save, by itself, 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.

Options

The forms of the save command that use options are:

save filename options

save filename variables options,

Each specifies a particular ASCII data format, as opposed to the binary MAT-file format, in which to save data. Valid option combinations are:

With these options...
Data is stored in:
-ascii
8-digit ASCII format
-ascii -double
16-digit ASCII format
-ascii -tabs
8-digit ASCII format, tab-separated
-ascii -double -tabs
16-digit ASCII format, tab-separated

Variables saved in ASCII format merge into a single variable that takes the name of the ASCII file. Therefore, loading the file filename shown above results in a single workspace variable named filename. Use the colon operator to access individual variables.

Limitations

Saving complex data with the -ascii keyword causes the imaginary part of the data to be lost, as MATLAB cannot load nonnumeric data ('i').

Remarks

The save 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.

Alternative syntax: The function form of the syntax, save('filename'), is also permitted.

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 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

The Application Program Interface Libraries contain C and Fortran routines to read and write MAT-files from external programs. It is important to use recommended access methods, rather than rely upon the specific file format, which is likely to change in the future.

See Also

fprintf     Write formatted data to file

fwrite      Write binary data to a file

load        Retrieve variables from disk



[ Previous | Help Desk | Next ]