save - Save contents of model workspace to a MAT-file - MATLAB (original) (raw)

Main Content

Save contents of model workspace to a MAT-file

Syntax

Description

save([mdlWks](#d126e741378),[fileName](#d126e741400)) saves the variables in the model workspace represented by theSimulink.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.

example

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 namedmyVars.mat.

save(mdlWks,'myVars.mat')

The MAT-file appears in your current folder.

Input Arguments

collapse all

Target model workspace, specified as aSimulink.ModelWorkspace object.

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

Example: 'myFile.mat'

Data Types: char

Version History

Introduced before R2006a