Documentation Center

  • Trial Software
  • Product Updates

save_system

Save Simulink system

Syntax

save_system
save_system(sys)
save_system(sys, newsysname)
save_system(sys, newsysname.slx)
save_system(sys, newsysname, Name,Value)
save_system(sys, 'exported_file_name.xml', 'ExportToXML', true)
filename = save_system(sys)

Description

save_system saves the current top-level system. If the system has not previously been saved, save_system creates a new file in the current folder.

save_system(sys) saves the top-level system that you specify in sys to a file using the current system name. sys must be a system name with no file extension. The system must be loaded. sys can be a string, a cell array of strings, a numeric handle, or an array of numeric handles. If you specify any options they apply to all the systems that you save.

save_system(sys, newsysname) saves the top-level system that you specify to a file using the new system name newsysname. The system must be loaded. newsysname can be a system name, or a filename with file extension and optional path, or empty. If you do not specify a file extension (.slx or .mdl) then save_system uses the file format specified in your Simulink® preferences.

save_system(sys, newsysname.slx) saves the top-level system sys to a new file newsysname in the SLX file format.

save_system(sys, newsysname, Name,Value) saves the system with additional options specified by one or more Name,Value pair arguments.

save_system(sys, 'exported_file_name.xml', 'ExportToXML', true) exports the system to a file in a simple XML format. Do not use ExportToXML with any other save_system options.

filename = save_system(sys) returns the fully-qualified file name of the file you saved.

save_system can save only entire systems. To save a subsystem, use the Simulink.SubSystem.copyContentsToBlockDiagram function to copy the subsystem contents to a new block diagram and then save it using save_system. See Simulink.SubSystem.copyContentsToBlockDiagram.

If you set the UpdateHistory property of the model to UpdateHistoryWhenSave, you see the following behavior:

  • When you save interactively, you see a dialog prompting for a comment to include in the model history.

  • When you save using save_system, you do not see a prompt for a comment. save_system reuses the previous comment, unless you set 'ModifiedComment' before saving:

    set_param(mymodel,'ModifiedComment',mycomment) 

Input Arguments

sys

Top-level system to save. 'sys' must be a system name, not a file name, i.e., without a file extension.

The system must be open. 'sys' can be a string, a cell array of strings, a numeric handle, or an array of numeric handles.

newsysname

New system name.

'newsysname' can be a system name, or a filename with file extension and optional path. If you do not specify a file extension (.slx or .mdl) then save_system uses the file format specified in your Simulink preferences.

'newsysname' can be empty ([]), in which case the current name is used. You must specify a newsysname argument before any name-value pair arguments even when you don't want to name a new sys, and in that case you leave it empty.

If 'sys' refers to more than one block diagram, 'newsysname' must be a cell array of new names.

This command displays an error if you enter any of the following as the new system name:

  • A MATLAB® keyword

  • 'simulink'

  • More than 63 characters

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: save_system(sys, newsysname, 'SaveModelWorkspace', true, 'BreakUserLinks', true, 'OverwriteIfChangedOnDisk', true)

'BreakAllLinks'

Logical value that indicates whether the function replaces links to library blocks with copies of the library blocks in the saved file. The 'BreakAllLinks' option affects any linked block, including user-defined and Simulink library blocks. Also accepts on or off.

true
false (default)

    Note   The 'BreakAllLinks' option can result in compatibility issues when upgrading to newer versions of Simulink software. For example:

    • Any masks on top of library links to Simulink S-functions will not upgrade to the new version of the S-function.

    • Any library links to masked subsystems in a Simulink library will not upgrade to the new subsystem behavior.

    • Any broken links prevent the automatic library forwarding mechanism from upgrading the link.

    If you have saved a model with broken links, use the Check model, local libraries, and referenced models for known upgrade issues option in the Model Advisor to scan the model for out-of-date blocks. You can then use the slupdate command to upgrade the Simulink blocks to their current versions. Subsequently running the Model Advisor lists any remaining third-party library and optional Simulink blockset blocks that are still out of date and need manual upgrading.

'BreakUserLinks'

Logical value that indicates whether the function replaces links to user-defined library blocks with copies of the library blocks in the saved file. Also accepts on or off.

true
false (default)

Default: false

'ErrorIfShadowed'

Logical value that indicates whether the function generates an error if the new name already exists on the MATLAB path or workspace. Also accepts on or off.

true
false (default)

'ExportToXML'

Logical value that indicates whether the function exports the specified block diagram to a file in a simple XML format. Specify the full name of the file, including an extension. The block diagram in memory does not change and no callbacks execute. Do not use this option with any other save_system options. Also accepts on or off.

true
false (default)

'ExportToVersion'

MATLAB release name, which specifies a previous Simulink version. save_system exports the system to a format that the specified previous Simulink version can load. You cannot export to your current version.

If the system contains functionality not supported by the specified Simulink software version, the command removes the functionality and replaces any unsupported blocks with empty masked subsystem blocks colored yellow. As a result, the converted system may generate different results.

To export to Release 2012a and later, you can specify model file format as SLX or MDL. If you do not specify a format, you export your default model file format.

SaveAsVersion is a legacy option for this argument that is also supported.

These version names are not case sensitive:

'R14'
'R14SP1'
'R14SP2'
'R14SP3'
'R2006A'
'R2006B'
'R2007A'
'R2007B'
'R2008A'
'R2008B'
'R2009A'
'R2009B'
'R2010A'
'R2010B'
'R2011A'
'R2011B'
'R2012A_MDL'
'R2012A_SLX'
'R2012B_MDL'
'R2012B_SLX'
'R2013A_MDL'
'R2013A_SLX'
'R2013B_MDL'
'R2013B_SLX'

'OverwriteIfChangedOnDisk'

Logical value that indicates whether to overwrite the file on disk (true) even if it has been externally modified since the system was loaded. To save the model regardless of whether the file has been changed on disk, supply the OverwriteIfChangedOnDisk option with value true.

If the file has changed on disk since the model was loaded, save_system displays an error to prevent the changes on disk from being overwritten, unless you use the OverwriteIfChangedOnDisk option set to true. Also accepts on or off.

true
false (default)

You can control whether save_system displays an error if the file has changed on disk by using the Saving the model option in the Model File Change Notification section of the Simulink Preferences dialog box. This preference is on by default.

'SaveModelWorkspace'

Logical value that indicates whether the function saves the contents of the model workspace. 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 Data Sources. Also accepts on or off.

true
false (default)

Output Arguments

filename

save_system returns the full name of the file that you saved, as a string. If you saved multiple files, the return value is a cell array of strings.

Examples

The following examples assume prerequisites such as: you have loaded a model and the folder where you want to save is writeable.

Save the current system.

save_system
 

Save the vdp system with the name vdp.

save_system('vdp')
 

Save the vdp system to a file with the name 'myvdp'. If you do not specify a file extension in the second argument (.slx or .mdl), then save_system uses the file format specified in your Simulink preferences.

save_system('vdp', 'myvdp')
 

Save the vdp system to another folder.

save_system('vdp', 'C:\TMP\vdp.slx')
 

Save an existing model mymodel to a different file and specifying the SLX file format:

save_system('mymodel', 'newsysname.slx')
 

Save the vdp system to a file with the name 'myvdp' and replace links to library blocks with copies of the library blocks in the saved file.

save_system('vdp','myvdp','BreakAllLinks', true)
 

Save the current model (with its current name), and break any library links in it:

save_system('mymodel','mymodel','BreakAllLinks',true)

or

save_system('mymodel',[],'BreakAllLinks',true)
 

Save the current model with a new name, but display an error (instead of saving) if something with this name already exists on the MATLAB path:

save_system('mymodel','mynewmodel','ErrorIfShadowed',true)
 

Prevent saving the vdp system with a new name if something with this name already exists on the MATLAB path. In this case save_system displays an error (instead of saving) because 'max' is the name of a MATLAB function.

save_system('vdp', 'max', 'ErrorIfShadowed', true)
 

Export the vdp system to Simulink Version R2008a with the name 'myvdp'. It does not replace links to library blocks with copies of the library blocks.

save_system('vdp','myvdp','ExportToVersion','R2008a')

Save the current model with a new name, save the model workspace, break any library links, and overwrite if the file has changed on disk:

save_system('mymodel', 'mynewmodel', 'SaveModelWorkspace', 
true, 'BreakAllLinks',true, 'OverwriteIfChangedOnDisk', true)

Return the full path name of the file that you saved, as a string. If you saved multiple files, the return value is a cell array of strings.

filename = save_system('mymodel')

Return the full path name of a system saved to a new file.

filename = save_system('mymodel', 'newmodelname')

More About

See Also

| |

Was this topic helpful?