Main Content


Save Simulink model


filename = save_system saves the current top-level model. If the model was not previously saved, save_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.


filename = save_system(sys) saves the model sys. The model must be open or loaded.


filename = save_system(sys,newsys) saves the model to a new file newsys. If you do not specify an extension, then save_system uses the file format specified in your Simulink® preferences.


filename = save_system(sys,newsys,Name,Value) saves the system with additional options specified by one or more Name,Value pair arguments. To use Name,Value pairs without saving to a new file, use [] for newsys.


collapse all

Create a model.


Save the model.


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.


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.


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.

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,


Save the model mymodel, breaking links to user-defined library blocks in the model.


Input Arguments

collapse all

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.

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 Model Names.

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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: save_system('mymodel','newmodel','SaveModelWorkspace',true,'BreakUserLinks',true,'OverwriteIfChangedOnDisk',true)

Option to allow dialog box prompts, specified as true, false, 'on', or 'off'. By default, warnings and error messages appear at the command line.

Option to return an error if the new name exists on the MATLAB path or workspace, specified as true, false, 'on', or '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)

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.

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.

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.

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

collapse all

Full name of saved file, returned as a character vector or a cell array of character vectors.

Introduced before R2006a