Save Simulink model
saves the current top-level
model. If the model was not previously saved, filename
= save_systemsave_system
creates a file in
the current folder.
To save a subsystem, instead use
Simulink.SubSystem.copyContentsToBlockDiagram
to copy the subsystem contents
to a new model. You can then save that model using save_system
. See Simulink.SubSystem.copyContentsToBlockDiagram
.
saves the system with additional options specified by one or more
filename
= save_system(sys
,newsys
,Name,Value
) Name,Value
pair arguments. To use Name,Value
pairs
without saving to a new file, use []
for newsys
.
Create a model.
new_system('newmodel')
Save the model.
save_system('newmodel')
Open the model vdp
. Save it to a model named myvdp
in the current folder. Without a file extension, the function saves the model using the format
specified in your Simulink preferences.
open_system('vdp') save_system('vdp','myvdp')
After you save the model by another name, the model is no longer open under its original
name. Open vdp
again and save it as an .mdl
file in the
current folder.
open_system('vdp') save_system('vdp','mynewvdp.mdl')
Save a model with a new name and return an error if something with this name exists on
the MATLAB® path. In this case,
save_system
displays an error because max
is the name
of a MATLAB function. The model is not saved.
open_system('vdp') save_system('vdp','max','ErrorIfShadowed',true)
Error using save_system (line 38) The model 'vdp' cannot be saved with the new name 'max', because this name is shadowing another name on the MATLAB path or in the workspace. Choose another name, or do not use the option 'ErrorIfShadowed'
Suppose that you have a model named mymodel
. Open the model and save
it to a model named newmodel
. Also save the model workspace, break links to
user-defined library blocks, and overwrite if the file has changed on disk,
open_system('mymodel') save_system('mymodel','mynewmodel','SaveModelWorkspace', true,'BreakUserLinks',true,'OverwriteIfChangedOnDisk',true)
Save the model mymodel
, breaking links to user-defined library blocks
in the model.
save_system('mymodel',[],'BreakUserLinks',true)
sys
— Name of model to saveName of model to save, specified as a character, cell array of character vectors, string array, handle, or array of handles. Do not use a file extension.
newsys
— File to save toFile to save to, specified as a character vector, cell array of character vectors, string
array, or, to use Name,Value
pairs without changing the file name,
[]
. You can specify a model name in the current folder or the full path
name, with or without an extension.
With no an extension, save_system
saves to the file format specified
in your Simulink preferences. Possible model extensions are .slx
and
.mdl
. With the 'ExportToXML'
option, use the extension
.xml
.
For information on rules for naming models, see Model Names.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
save_system('mymodel','newmodel','SaveModelWorkspace',true,'BreakUserLinks',true,'OverwriteIfChangedOnDisk',true)
'AllowPrompt'
— Allow dialog box promptsfalse
(default) | true
| 'on'
| 'off'
Option to allow dialog box prompts, specified as true
,
false
, 'on'
, or 'off'
. By default,
warnings and error messages appear at the command line.
'BreakAllLinks'
— Replace links to library blocksfalse
(default) | true
| 'on'
| 'off'
Option to, in the saved file, replace links to library blocks with copies of the library
blocks, specified as true
, false
,
'on'
, or 'off'
. This option affects user-defined
blocks and Simulink library blocks.
Caution
The 'BreakAllLinks'
option can result in compatibility issues when
upgrading to newer versions of Simulink. For example:
Any masks on top of library links to Simulink S-functions do not upgrade to the new version of the S-function.
Any library links to masked subsystems in a Simulink library do not upgrade to the new subsystem behavior.
Any broken links prevent the library forwarding mechanism from upgrading the link.
If you saved a model with broken links to built-in libraries, use the Upgrade Advisor to scan the model for out-of-date blocks. Then upgrade the Simulink blocks to their current versions.
'BreakUserLinks'
— Replace links to user-defined blocksfalse
(default) | true
| 'on'
| 'off'
Option to, in the saved file, replace links to user-defined library blocks with copies
of the library blocks, specified as true
, false
,
'on'
, or 'off'
.
'BreakToolboxLinks'
— Replace links to built-in library blockfalse
(default) | true
| 'on'
| 'off'
Option to, in the saved file, replace links to built-in library blocks with copies of
the library blocks, specified as true
, false
,
'on'
, or 'off'
. This option affects Simulink library blocks and blocks from libraries supplied with MathWorks® toolboxes or blocksets.
'ErrorIfShadowed'
— Return an error if name existsfalse
(default) | true
| 'on'
| 'off'
Option to return an error if the new name exists on the MATLAB path or workspace, specified as true
,
false
, 'on'
, or 'off'
.
'ExportToXML'
— Export model to XML formatfalse
(default) | true
| 'on'
| 'off'
Option to export the model to a file in a simple XML format, specified as
true
, false
, 'on'
, or
'off'
. Specify the full name of the file, including the
.xml
extension. The block diagram in memory does not change and no
callbacks execute. Use this option without any other Name,Value
pair
arguments. This option warns and will be removed in a future release.
Example: save_system('mymodel','exportfile.xml','ExportToXML',true)
'ExportToVersion'
— MATLAB release name to export tostring scalar
MATLAB release name to export to, specified in either of these forms (not case sensitive). You can export to seven years of previous releases.
Release name, for example, 'R2013B'
,
'R2016B'
Release name, followed by an underscore and then the extension, for example,
'R2016A_SLX'
, 'R2014A_MDL'
. If you do not specify
an extension, you export to the file format specified in your Simulink preferences.
save_system
exports the system such that the specified
Simulink version can load it. If the system contains functionality not supported by the
specified Simulink version, the command removes the functionality in the exported file. It also
replaces unsupported blocks with empty masked subsystem blocks colored yellow. As a result,
the exported system might generate different results.
Alternatively, use Simulink.exportToVersion
or, interactively, the Export to Previous Version dialog
box.
To export a project to previous releases, see Export a Project to a Previous Version.
'OverwriteIfChangedOnDisk'
— Overwrite filefalse
(default) | true
| 'on'
| 'off'
Option to overwrite the file on disk even if it has been modified since the system was
loaded, specified as true
, false
,
'on'
, or 'off'
. By default, if the file changed on
disk since the model was loaded, save_system
displays an error to prevent
the changes on disk from being overwritten.
You can control whether save_system
displays an error if the file has
changed on disk using a Simulink preference. In the Model File pane of the Simulink Preferences dialog box, under Change Notification, select
Saving the model. This preference is on by default.
'SaveDirtyReferencedModels'
— Save referenced models with unsaved changesfalse
(default) | true
| 'on'
| 'off'
Option to save referenced models that contain unsaved changes while also saving the
model, specified as true
, false
,
'on'
, or 'off'
. By default, attempting to save a model
that contains unsaved referenced models return an error.
'SaveModelWorkspace'
— Save model workspacefalse
(default) | true
| 'on'
| 'off'
Option to save the contents of the model workspace, specified as
true
, false
, 'on'
, or
'off'
. The model workspace DataSource
must be a
MAT-file. If the data source is not a MAT-file, save_system
does not save
the workspace. See Specify Source for Data in Model Workspace.
filename
— Name of saved fileFull name of saved file, returned as a character vector or a cell array of character vectors.