| Simulink® | ![]() |
save_system
save_system('sys')
save_system('sys', 'newname')
save_system('sys', 'newname', 'BreakAllLinks', true)
save_system('sys', 'newname', 'BreakUserLinks', true)
save_system('sys', 'newname', 'SaveModelWorkspace', true)
save_system('sys', 'newname', 'ErrorIfShadowed', true)
save_system('sys', 'newname', 'SaveAsVersion', 'version')
save_system('sys', 'newname', 'OverWriteIfChangedOnDisk', true)
save_system('sys', 'newname', 'SaveModelWorkspace', true,
'BreakLinks', true, 'OverwriteIfChangedOnDisk', true)
save_system saves the current top-level system to a file with its current name.
save_system('sys') saves the specified top-level system to a file with its current name. The system must be open. 'sys' can be a string, a cell array of strings, a numeric handle, or an array of numeric handles.
save_system('sys', 'newname') saves the specified top-level system to a file with the specified new name. The system to be saved must be open. The new name can be a file name, in which case Simulink software saves the system in the working directory, or a fully qualified pathname. On UNIX® systems, the fully qualified pathname can start with a tilde (~), signifying your home directory.
'newname' can be empty ([]), in which case the current name is used. If 'sys' refers to more than one block diagram, 'newname' must be a cell array of new names.
This command displays an error if you enter any of the following as the new model name:
A MATLAB® keyword
'simulink'
More than 63 characters
Additional arguments must be supplied as name-value pairs, in any order. Allowed names are:
ErrorIfShadowed: true or false (default: false)
Generates an error if the specified new name already exists on the MATLAB path or workspace.
BreakAllLinks: true or false (default: false)
Replaces links to library blocks with copies of the library blocks in the saved file. The 'BreakLinks' option affects any linked block, including user-defined and Simulink library blocks.
Note The 'BreakAllLinks' option can result in compatibility issues when upgrading to newer versions of Simulink software. For example:
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 to be manually upgraded. |
BreakUserLinks: true or false (default: false)
Replaces links to user-defined library blocks with copies of the library blocks in the saved file.
SaveAsVersion: MATLAB version name (default: current)
Saves the system in a form that can be loaded by a specified version of Simulink software. Valid values include R12, R12P1, R13, R13SP1, R14, R14SP1, R14SP2, R14SP3, R2006A, R2006B, R2007A. These are case insensitive. If the system to be saved contains blocks not supported by the specified Simulink software version, the command replaces the unsupported blocks with empty masked subsystem blocks colored yellow. As a result, the converted system may generate incorrect results.
OverwriteIfChangedOnDisk: true or false (default: false)
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. This error appears only if the Saving the model option in the Model File Change Notification section of the Simulink Preferences dialog is selected.
To save the model regardless of whether the file has been changed on disk supply the OverwriteIfChangedOnDisk option with value true.
SaveModelWorkspace: true or false (default: false)
If the model workspace DataSource is a MAT-file, this command also saves the contents of the model workspace. 'SaveModelWorkspace' is most useful when DataSource is a MAT-file.
The same options are applied to all the block diagrams that are saved.
save_system returns the full name of the file that was saved, as a string. If multiple files were saved, the return value is a cell array of strings.
save_system can save only entire block diagrams, but the utility function Simulink.SubSystem.copyContentsToBlockDiagram can be used to copy the contents of a subsystem into a new block diagram, which can then be saved using save_system.
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 are not prompted for a comment. save_system reuses the previous comment, unless you set 'ModifiedComment' before saving, as follows:
set_param(mymodel,'ModifiedComment',mycomment)
This command saves the current system.
save_system
This command saves the vdp system with the name vdp.
save_system('vdp')This command saves the vdp system to a file with the name 'myvdp'.
save_system('vdp', 'myvdp')This command saves the vdp system to another directory.
save_system('vdp', 'C:\TMP\vdp.mdl')This command saves the vdp system to a file with the name 'myvdp' and replaces links to library blocks with copies of the library blocks in the saved file.
save_system('vdp','myvdp','BreakLinks', true)Both of these commands save the current model (with its current name), and break any library links in it:
save_system('mymodel,'mymodel','BreakLinks',true)
save_system('mymodel,[],'BreakLinks',true)This command saves the current model with a new name, but displays an error (instead of saving) if something with this name already exists on the MATLAB path:
save_system('mymodel','mynewmodel','ErrorIfShadowed',true)
This command tries to save the vdp system to a file with the name 'max', but returns an error because 'max' is the name of a MATLAB function.
save_system('vdp', 'max', 'ErrorIfShadowed', true)This command saves the vdp system to Simulink Version R13SP1 with the name 'myvdp'. It does not replace links to library blocks with copies of the library blocks.
save_system('vdp','myvdp','SaveAsVersion','R13SP1')This command saves the current model with a new name, saves the model workspace, breaks any library links, and overwrites if the file has changed on disk:
save_system('mymodel, 'mynewmodel', 'SaveModelWorkspace',
true, 'BreakLinks',true, 'OverwriteIfChangedOnDisk', true)
This command returns the full path name of the file that was saved, as a string. If multiple files were saved, the return value is a cell array of strings.
filename = save_system('mymodel')
close_system, new_system, open_system
![]() | replace_block | set_param | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |