save

Save variables in the MAT file, filename.

Syntax

save(filename)

save(filename, format)

save(filename, variables)

save(filename, variables, format)

save(filename, ..., options)

Inputs

filename
Name of the MAT file to save. By default, the file saved will be in -v5 binary format and overwritten, unless specified by format or options.
Type: string
format
Optional argument specifing the format of filename.
-5
-v5
filename is in v5 format. This is the default format that filename is saved in.
Type: string
-7.3
-v7.3
filename is in v7.3 format.
Type: string
options
-append
filename will not be overwritten and the variables to be saved will be appended to the existing file, it is exists.
Type: string
-ascii
filename will be savedd as a text file and real, numerical data will be written.
Type: string
variable
Optional list of the variables to save, separated by a comma.
If no variable is specified, all variables are saved. Function handles cannot be saved and will appear as 'NaN' in filename. The single command can be used to mark a scalar/complex/2DMatrix variable as a single precision datatype so that single precision data can be written out in filename. If variable is a graphics or computer vision handle, it will be saved as a double in filename.
Type: string

Examples

Save data to a .mat file using save function:
st='hello';
M = [1923.71288  4023.03575  9768.82832  9195.83701  104.13143  4261.35201];

save('file.mat')             % Saves all varaibles
save('file.mat','M')         % Save specific variable
save('file.mat','M','-v7.3') % Save specific variable with v7.3 format
Save a 2D matrix with single precision data in a .mat file:
M = [1923.71288  4023.03575  9768.82832  9195.83701  104.13143  4261.35201];
single(M);
save('file.mat','M');
Append variables to an existing file:
M = [1923.71288  4023.03575  9768.82832  9195.83701  104.13143  4261.35201];
save('file.mat');              % Overwrite, if file exists
a = 10;
save('file.mat', '-append');   % Append to previously existing file