Navigation

Operators and Keywords

Function List:

C++ API

: save file
: save options file
: save options file v1 v2
: save options file -struct STRUCT f1 f2
: save "-" v1 v2
: s = save ("-" v1 v2 …)

Save the named variables v1, v2, …, in the file file.

The special filename ‘-’ may be used to return the content of the variables as a string. If no variable names are listed, Octave saves all the variables in the current scope. Otherwise, full variable names or pattern syntax can be used to specify the variables to save. If the -struct modifier is used, fields f1 f2 … of the scalar structure STRUCT are saved as if they were variables with corresponding names. Valid options for the save command are listed in the following table. Options that modify the output format override the format specified by save_default_options.

If save is invoked using the functional form

save ("-option1", …, "file", "v1", …)

then the options, file, and variable name arguments (v1, …) must be specified as character strings.

If called with a filename of "-", write the output to stdout if nargout is 0, otherwise return the output in a character string.

-append

Append to the destination instead of overwriting.

-ascii

Save a single matrix in a text file without header or any other information.

-binary

Save the data in Octave’s binary data format.

-float-binary

Save the data in Octave’s binary data format but only using single precision. Only use this format if you know that all the values to be saved can be represented in single precision.

-hdf5

Save the data in HDF5 format. (HDF5 is a free, portable binary format developed by the National Center for Supercomputing Applications at the University of Illinois.) This format is only available if Octave was built with a link to the HDF5 libraries.

-float-hdf5

Save the data in HDF5 format but only using single precision. Only use this format if you know that all the values to be saved can be represented in single precision.

-V7
-v7
-7
-mat7-binary

Save the data in MATLAB’s v7 binary data format.

-V6
-v6
-6
-mat
-mat-binary

Save the data in MATLAB’s v6 binary data format.

-V4
-v4
-4
-mat4-binary

Save the data in the binary format written by MATLAB version 4.

-text

Save the data in Octave’s text data format. (default).

-zip
-z

Use the gzip algorithm to compress the file. This works equally on files that are compressed with gzip outside of octave, and gzip can equally be used to convert the files for backward compatibility. This option is only available if Octave was built with a link to the zlib libraries.

The list of variables to save may use wildcard patterns containing the following special characters:

?

Match any single character.

*

Match zero or more characters.

[ list ]

Match the list of characters specified by list. If the first character is ! or ^, match all characters except those specified by list. For example, the pattern [a-zA-Z] will match all lower and uppercase alphabetic characters.

Wildcards may also be used in the field name specifications when using the -struct modifier (but not in the struct name itself).

Except when using the MATLAB binary data file format or the ‘-ascii’ format, saving global variables also saves the global status of the variable. If the variable is restored at a later time using ‘load’, it will be restored as a global variable.

The command

save -binary data a b*

saves the variable ‘a’ and all variables beginning with ‘b’ to the file data in Octave’s binary format.

See also: load, save_default_options, save_header_format_string, dlmread, csvread, fread.

Package: octave