save

Purpose

Save workspace variables on disk.

Synopsis

save
save  filename
save  filename  variables
save  filename  keywords
save  filename  variables  keywords

Description

save and load are the MATLAB commands to store and retrieve variables on disk. They can also import and export ASCII data files. MAT-files are full-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.

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 uses file filename.mat instead of the default matlab.mat.

save filename variables saves a selection of the current workspace variables by listing the variables after the filename.

save filename keywords specifies characteristics for data to be saved in ASCII format, instead of in the binary MAT-file format. Valid keywords are -ascii, -double, and -tabs.The command

save  filename  variables  -ascii
uses 8-digit ASCII form.

The command

 save  filename  variables  -ascii  -double
uses 16-digit ASCII form.

The data can be separated with tabs by appending the keyword tabs.

save  filename  variables  -ascii  -tabs
save  filename  variables  -ascii  -double  -tabs
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.

The ASCII data must be in matrix form, or MATLAB may be unable to use the data when you load it.

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

If the filename is the special string stdio, save sends the data as standard output.

Algorithm

The binary formats used by save depend on the size and type of each matrix. Matrices with any noninteger entries and matrices with 10,000 or fewer elements are saved in floating-point formats requiring eight bytes per real element. Matrices with all integer entries and more than 10,000 elements are saved in the following formats, requiring fewer bytes per element.

             Element Range  Bytes per Element
          
                 [0:255]        1
               [0:65535]        2
          [-32767:32767]        2
        [-2^31+1:2^31-1]        4
                   other        8
The structure of MAT-files is discussed in detail in the External Interface Guide. The External Interface Library contains 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, fwrite, load

(c) Copyright 1994 by The MathWorks, Inc.