Main Content

save

Save contents of model workspace to a MAT-file

Description

example

save(mdlWks,fileName) saves the variables in the model workspace represented by the Simulink.ModelWorkspace object mdlWks to the MAT-file specified by fileName.

When you set the DataSource property of the model workspace to 'MAT-File' or 'MATLAB File', to save to the file that acts as the external data source of the model, use saveToSource instead of save.

Examples

collapse all

Open the example model vdp.

openExample('simulink_general/VanDerPolOscillatorExample')

Create a Simulink.ModelWorkspace object that represents the model workspace of vdp.

mdlWks = get_param('vdp','ModelWorkspace');

Create some variables in the model workspace.

assignin(mdlWks,'myVar',5.12)
assignin(mdlWks,'myOtherVar',7.22)

Save the variables to a new MAT-file named myVars.mat.

save(mdlWks,'myVars.mat')

The MAT-file appears in your current folder.

Input Arguments

collapse all

Target model workspace, specified as a Simulink.ModelWorkspace object.

Name of the target MAT-file, specified as a character vector.

Example: 'myFile.mat'

Data Types: char

Version History

Introduced before R2006a