|On this page…|
To tell whether a model needs saving, look at the title bar in the Simulink® Editor. If the model needs saving, an asterisk appears next to the model name in the title bar.
To determine programmatically whether a model needs saving, use the model parameter Dirty. For example:
if strcmp(get_param(gcs, 'Dirty'), 'on') save_system; end
To save a model for the first time, in the Simulink Editor, select File > Save. Provide a location and name for the model file.
The total number of characters must not be greater than a certain maximum, usually 63 characters. To find out whether the maximum for your system is greater than 63 characters, use the MATLAB namelengthmax command.
If you are saving a model whose model file was previously saved:
To replace the file contents, in the Simulink Editor, select File > Save.
To save the model with a new name or location, in the Simulink Editor, select File > Save As.
Note: See also Upgrade Models to SLX.
Simulink saves the model by generating a specially formatted file called the model file that contains the model (block diagram) and block properties. The Simulink software follows this process while saving a model:
If an error occurs during this process, Simulink:
Renames the temporary file to the name of the original model file
Writes the current version of the model to a file with an .err extension
Issues an error message
If an error occurs in Step 2 of the save process, then Step 3 is omitted and Steps 4 and 5 are performed.
You save new models and libraries in the SLX format by default, with file extension .slx. SLX is a compressed package that conforms to the Open Packaging Conventions (OPC) interoperability standard. SLX stores model information using Unicode® UTF-8 in XML and other international formats. Saving Simulink models in the SLX format:
Typically reduces file size compared to MDL. The file size reduction between MDL and SLX varies depending on the model.
Solves some problems in previous releases with loading and saving MDL files containing Korean and Chinese characters.
You can specify your file format for saving new models and libraries with the Simulink preference File format for new models and libraries.
If you upgrade an MDL file to SLX file format, the file contains the same information as the MDL file, and you always have a backup file. All functionality and APIs that currently exist for working with models, such as the get_param and set_param commands, are also available when using the SLX file format. If you upgrade an MDL file to SLX file format without changing the model name or location, then Simulink creates a backup file by renaming (if writable) and Simulink does not remove the MDL file.
If you save an existing MDL file using File > Save, Simulink respects the file's current format and saves your model in MDL format.
To save an existing MDL file in the SLX file format,
Select File > Save As.
Leave the default Save as type as SLX, and click Save.
Simulink saves your model in SLX format, and creates a backup file by renaming the MDL (if writable) to mymodel.mdl.releasename, e.g., mymodel.mdl.R2010b.
Alternatively, use save_system:
save_system mymodel mymodel.slx
This command creates mymodel.slx, and if the existing file mymodel.mdl is writable it is renamed mymodel.mdl.releasename.
SLX files take precedence over MDL files, so if both exist with the same name and you do not specify a file extension, you load the SLX file.
Simulink Projects can help you migrate files to SLX. For an example, see Upgrade Model Files to SLX and Preserve Revision History.
Caution If you use third-party source control tools, be sure to register the model file extension .slx as a binary file format. If you do not, these third-party tools might corrupt SLX files when you submit them.
|Operations with Possible Compatibility Considerations when using SLX||What Happens||Action|
|Hard-coded references to file names with extension .mdl.||Scripts cannot find or process models saved with new file extension .slx.||Make your code work with both the .mdl and .slxextension. |
Use functions like which and what instead of strings with .mdl.
|Third-party source control tools that assume a text format by default.||Binary format of SLX files can cause third-party tools to corrupt the files when you submit them.||Register .slx as a binary file format with third-party source control tools. Also recommended for .mdl files. See Register Model Files with Source Control Tools.|
|Changing character encodings.||Some cases are improved, e.g., SLX solves some problems in previous releases with loading and saving MDL files containing Korean and Chinese characters. However, sharing models between different locales remains problematic.||See SLX Files and Character Encodings.|
When you save a model, the current character encoding is used to encode the text stored in the model file. With MDL files, this can lead to model corruption if you save a model whose original encoding differs from current encoding.
If you change character encoding, it is possible to introduce characters that cannot be represented in the current encoding. If this is the case, the model is saved as model.mdl.err, where model is the model name, leaving the original model file unchanged. Simulink also displays an error message that specifies the line and column number of the first character which cannot be represented.
To recover from this error, either:
Save the model in SLX format (see Saving Models in the SLX File Format).
Use the following procedure to locate and remove characters one by one.
Use a text editor to find the character in the .err file at the position specified by the save error message.
Find and delete the corresponding character in the open model and resave the model.
Repeat this process until you are able to save the model without error.
It's possible that your model's original encoding can represent all the text changes that you've made in the current session, albeit incorrectly. For example, suppose you open a model whose original encoding is A in a session whose current encoding is B. Further suppose that you edit the model to include a character that has different encodings in A and B and then save the model. If in addition the encoding for x in B is the same as the encoding for y in A, and if you insert x in the model while B is in effect, save the model, and then reopen the model with A in effect the Simulink software will display x as y. To alert you to the possibility of such corruptions, the software displays a warning message whenever you save a model in which the current and original encoding differ but the original encoding can encode, possibly incorrectly, all of the characters to be saved in the model file.
Saving Simulink models in the SLX format typically reduces file size and solves some problems in previous releases with loading and saving MDL files containing Korean and Chinese characters.
Considerations for choosing a model file format:
Use SLX if you are loading and saving models with Korean or Chinese characters
Use SLX if you would benefit from a compressed model file
Whether you use SLX or MDL, Simulink can detect and warn if models contain characters unsupported in the current locale. For SLX, you can use the Model Advisor to help you, see Check file for foreign characters.
You can export (save) a model created with the latest version of the Simulink software in a format used by an earlier version, such as Simulink 7.0 (R2007b). For example, you might want to perform such an export to make a model available to colleagues who only have access to a previous version of the Simulink product.
To export a model in an earlier format:
In the Simulink Editor, select File > Save. This saves a copy in the latest version of Simulink. This step avoids compatibility problems.
The Export to Previous Version dialog box appears.
When you export a model to a previous version's format, the model is saved in the earlier format, regardless of whether the model contains blocks and features that were introduced after that version. If the model does contain blocks or use features that postdate the earlier version, the model might not give correct results when you run it in the earlier version of Simulink software. In addition, Simulink converts blocks that postdate an earlier version into yellow empty masked Subsystem blocks. For example, if you export a model to Release R2007b, and the model contains Polynomial blocks, Simulink converts the Polynomial blocks into yellow empty masked Subsystem blocks. Simulink also removes any unsupported functionality from the model.
You can open a model created in an earlier version of Simulink and export that model to a different earlier version. To prevent compatibility problems, use the following procedure if you need to save a model from one earlier version to another earlier version.
Use the current version of Simulink to open the model created with the earlier version.
Before you make any changes, save the model in the current version by selecting File > Save.
After saving the model in the current version, you can change and resave it as needed.
Save the model in the earlier version of Simulink by selecting File > Export Model to > Previous Version.
Start the earlier Simulink version and use it to open the model that you exported to that earlier version.
Save the model in the earlier version by selecting File > Save.
You can now use the model in the earlier version of Simulink exactly as you could if it had been created in that version.
See also the Simulink preferences that can help you work with models from earlier versions: