save_system
Save Simulink model
Syntax
Description
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 model with additional options specified by one or more filename
= save_system(sys
,Name,Value
) Name,Value
pair arguments.
saves the model to a new file 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
.
Examples
Save New Model
Create a model.
new_system('myModel')
Save the model.
save_system('myModel')
Save Model with Another Name
Open the example. Then, open the vdp
model.
open_system('vdp')
Save the model in the current folder with the name myModel
.
save_system('vdp','myModel')
Without a file extension, the function saves the model in the format specified by your Simulink® preferences.
After you save the model by another name, the model is no longer open under its original name.
Open the vdp
model again.
open_system('vdp')
Save the model as a .mdl
file in the current folder.
save_system('vdp','myModel2.mdl')
Return Error If Name Exists
Suppose you have a model named myModel
.
Save the model with a new name and return an error if something with this name exists on the MATLAB® path.
open_system('myModel') save_system('myModel','max','ErrorIfShadowed',true)
Error using save_system (line 38) The model 'myModel' 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'
In this case, save_system
displays an error because
max
is the name of a MATLAB function. The model is not saved.
Save Model to Different Name with Options
Suppose you have a model named myModel
.
Open the model.
open_system('myModel')
Save the model with the name myModel2
. Also save the model workspace,
break links to user-defined library blocks in the model, and overwrite if the file has changed
on the disk.
save_system('myModel','myModel2','SaveModelWorkspace', true,'BreakUserLinks',true,'OverwriteIfChangedOnDisk',true)
Save Model to Same Name with Options
Suppose you have a model named myModel
.
Open the model.
open_system('myModel')
Save the model without changing its name. Break links to user-defined library blocks in the model.
save_system('myModel','BreakUserLinks',true)
Input Arguments
sys
— Name of model to save
character vector | cell array of character vectors | string array | handle | array of handles
Name 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 to
character vector | cell array of character vectors | string array | [ ]
File 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 Choose Valid Model File Names.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: save_system('mymodel','newmodel','SaveModelWorkspace',true,'BreakUserLinks',true,'OverwriteIfChangedOnDisk',true)
AllowPrompt
— Allow dialog box prompts
false
(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 blocks
false
(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. See Maintain Compatibility of Library Blocks Using Forwarding Tables.
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 blocks
false
(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 block
false
(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 bat365® toolboxes or blocksets.
ErrorIfShadowed
— Return an error if name exists
false
(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 format
false
(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 to
character vector | string 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 model such that the specified
Simulink version can load it. If the model 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 model 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 file
false
(default) | true
| 'on'
| 'off'
Option to overwrite the file on disk even if it has been modified since the model 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 changes
false
(default) | true
| 'on'
| 'off'
Option to save referenced models that have unsaved changes while saving changes to their
parent model, specified as true
, false
,
'on'
, or 'off'
. This option applies to models that are
directly referenced by each model that is saved. If the parent model of a dirty referenced
model is not saved, the dirty referenced model is not saved.
Suppose you have a model hierarchy in which model A
references model
B
, and model B
references model C
.
If models B
and C
both have unsaved changes, they are
both saved. If model C
has unsaved changes but model B
does not have unsaved changes, neither model is saved.
By default, attempting to save a model that contains unsaved referenced models return an error.
SaveModelWorkspace
— Save model workspace
false
(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.
Output Arguments
filename
— Name of saved file
character vector | cell array of character vectors
Full name of saved file, returned as a character vector or a cell array of character vectors.
Version History
Introduced before R2006a
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)