Main Content

saveToSource

Save model workspace changes to the external data source of the model workspace

Description

example

saveToSource(mdlWks) saves the variables in the model workspace represented by the Simulink.ModelWorkspace object mdlWks to the MAT-file or script file specified by the FileName property of the model workspace.

When you set the DataSource property of the model workspace to 'MAT-File' or 'MATLAB File', the FileName property specifies the name of the file that acts as the external data source of the workspace. As you make changes to the variables in the model workspace, use saveToSource to permanently save the changes in the external data source.

Examples

collapse all

Open the example model vdp.

open_system('vdp')

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)

Configure the model workspace to use a MAT-file named myVars.mat as the data source.

mdlWks.DataSource = 'MAT-File';
mdlWks.FileName = 'myVars.mat';

Save the variables to the external data source (the MAT-file).

saveToSource(mdlWks)

The file appears in your current folder.

Input Arguments

collapse all

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

Version History

Introduced before R2006a