saveToSource - Save model workspace changes to the external data source of the model
workspace - MATLAB ([original](https://in.mathworks.com/help/simulink/slref/simulink.modelworkspace.savetosource.html)) ([raw](?raw))
Main Content
Save model workspace changes to the external data source of the model workspace
Syntax
Description
saveToSource([mdlWks](#d126e741530))
saves the variables in the model workspace represented by the Simulink.ModelWorkspace
object mdlWks
to the MAT-file or script file specified by theFileName
property of the model workspace.
When you set the DataSource
property of the model workspace to 'MAT-File'
or 'MATLAB File'
, theFileName
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.
If an object loaded into the model workspace uses a Simulink.CoderInfo object to specify code generation settings, Simulink® removes the Simulink.CoderInfo
object and saves the information in the code mapping object for the model.
Examples
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)
Configure the model workspace to use a MAT-file namedmyVars.mat
as the data source.
mdlWks.DataSource = 'MAT-File'; mdlWks.FileName = 'myVars.mat';
Save the variables to the external data source (the MAT-file).
The file appears in your current folder.
Input Arguments
Target model workspace, specified as aSimulink.ModelWorkspace
object.
Version History
Introduced before R2006a