save

Save variables in the MAT file, filename.

Syntax

save(filename, variables)

save(filename, variables, format)

save(filename)

save(filename, format)

Inputs

filename
Path and name of the MAT file to save.
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.
Type: string
format
Specifies the format of the file to save. If omitted, format 5 is assumed.
Type: string
Valid entries for format:
  • '-v5' - indicates to save using v5 format.
  • '-v7.3' - indicates to save using v7.3 format.

Examples

Save data to a .mat file using save function:

% create some string
st='hello';
% create a matrix
M = [ 1923.71288  4023.03575  9768.82832  9195.83701  104.13143  4261.35201   ];
% save to file
save('file.mat')
% save only the matrix to file
save('file.mat','M')
% save only the matrix to file, with v5 format
save('file.mat','M','-v5')
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');