| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
| On this page… |
|---|
A protected model is a referenced model from which all block and line information have been eliminated. Protecting a model does not use encryption technology. A protected model can be distributed without revealing the intellectual property that it embodies. When simulated, a protected model gives the same results that its source model does when referenced in Accelerator mode.
You can use a protected model much as you could any other referenced model. Simulink tools work with protected models to the extent possible given that the model's contents are obscured. For example, the Model Explorer and the Model Dependency Viewer show the hierarchy under an ordinary referenced model, but not under a protected model. Signals in a protected model cannot be logged, because the log could reveal information about the protected model's contents.
When a referenced model requires object definitions or tunable parameters that are defined in the MATLAB base workspace, the protected version of the model may need some or all of those same definitions when it executes as part of a third-party model. Simulink provides techniques for identifying and obtaining the needed data, and then packaging it with the protected model for delivery.
Protecting a model requires a Real-Time Workshop license, which makes code generation capabilities available for use internally when creating the protected version of the model. A third party that receives the model does not need a Real-Time Workshop license to use the model, and cannot use Real-Time Workshop to generate code for the model or any model that references it.
The Model Protection facility is a set of Simulink commands, tools, and techniques that you can use to protect a referenced model, identify definitions that it needs, and package the model and any definitions for delivery to a third party. The receiver can then unpackage and use the protected model and any definitions. To see a demo of the Model Protection facility, access MATLAB Online Help and choose:
Demos > Simulink > Modeling Features > Model Reference > Model Reference Protected Models
The Model Protection facility is not an integrated unit like a viewer or editor, and has only a command-line interface. To begin using the facility, you execute a protect command in the MATLAB base workspace. See the Simulink.ReferencedModel.protect reference page for complete information about the protect command. The syntax of the command is:
[harnessHandle, neededVars] = Simulink.ModelReference.protect (model, 'Param', Val, ...)
You can use the protect command and its arguments to:
Specify the model to be protected. See Protecting a Referenced Model.
Specify the directory in which the protect command will place the protected model. See Specifying an Output Directory.
Create a harness model, which contains a model block that is preconfigured to work with the protected model. See Creating a Harness Model.
Obtain a list that includes the names of all base workspace entities that the model needs in order to run. See Obtaining Object and Variable Names.
For simplicity, Protecting a Referenced Model shows you how to use each of these capabilities separately when protecting a model. In practice, you can use any or all of the capabilities at the same time, and specify optional argument pairs in any order.
After you have created or obtained all the components that you intend to provide to the receiver, you can package them for delivery as described in Packaging a Protected Model. The receiver of the model will need instructions for unpacking the component(s) and using them in a model. The necessary instructions appear in Using a Protected Model.
Protecting a model requires meeting all requirements listed in Simulink Model Referencing Requirements, as well as the following:
You must have a Real-Time Workshop license, which you can obtain via http://www.mathworks.com.
Your platform and your version of Simulink must match those on which the protected model will be used.
The model to be protected must be available on the MATLAB path and have no unsaved changes.
The model to be protected cannot reference any subordinate protected model directly or indirectly.
Model protection is also subject to certain limitations, as described in Model Protection Limitations.
If you need nothing but the protected model itself, with no harness model or list of names, all you need to do is specify the source model to the protect command.
Be sure that the model to be protected and the model hierarchy that contains it:
Meet the Model Protection Requirements
Respect the Model Protection Limitations .
In the MATLAB Command Window, execute:
Simulink.ModelReference.protect(model)
The model is the name or handle of the model to be protected, or the full path to the model to be protected. If the model block uses variants, only the active variant is protected. See Using Model Reference Variants.
The protect command creates a protected version of the model and stores it by default in the current working directory. You can change this default as described in Specifying an Output Directory. The protected model has the same name as the source model, with the suffix .mdlp. In the MATLAB Directory Browser, a small image of a lock appears in the upper left corner of a protected model's icon.
Never change the name of a protected model. If you rename a protected model, or change its suffix, the model will be unusable until its original name and suffix are restored. You also cannot change a protected model internally in any way: any internal change will destroy the usability of the file.
To specify a directory other than the current working directory to contain the protected model, use the optional Path argument:
Simulink.ModelReference.protect(model, 'Path', pathname)
where pathname is a fully qualified pathname of an accessible writeable directory. The command stores the protected model in the indicated directory.
When the protect command protects a model, it can also create a harness model. This model contains a Model block that is preconfigured to work with the protected model. This Model block:
Names the protected model as its referenced model.
Has the same number of input and output ports as the protected model
Defines any model reference arguments that the protected model uses, but provides no values
To create a harness model when protecting a model, specify the optional Harness argument as true. The protect command returns the handle of the harness model in the first output argument:
[harnessHandle] = Simulink.ModelReference.protect(model, 'Harness', true)The harness model opens as a new untitled model that contains only the described Model block. This block, and any other Model block that references a protected model, shows a small image of a lock in its upper left corner. You can:
Save the harness model under any name and use it as needed
Use the handle in harnessHandle to manipulate the model programmatically
Copy the Model block into another model, where it functions as the interface to the protected model
See Packaging a Protected Model for more about how to use a harness model and the Model block that it contains.
When a referenced model requires any object or tunable parameter that is defined in the MATLAB base workspace, executing the protected version of the model will require that same entity if it is:
A global tunable parameter
A global Data Store Memory
Any of the following objects used by a signal that connects to a root-level model Inport or Outport:
Simulink.Signal
Simulink.Bus
Simulink.Alias
Simulink.NumericType that is an alias
When you protect a model, you must obtain the definitions of all necessary base workspace entities and ship them along with the model. The necessary steps for obtaining the definitions are:
Obtain candidate names
Prune unneeded names
Save workspace definitions
See Packaging a Protected Model for information about how to ship the base workspace definitions.
Obtaining Candidate Names. When the protect command executes, it always generates a cell array that includes the names of all base workspace entities that the protected model might need. You can obtain this array by accepting the second return value when you execute the command:
[~, neededVars] = Simulink.ModelReference.protect(model)The tilde (~) operator discards the first argument, or you could accept it if you create a harness model at the same time. The returned cell array neededVars is guaranteed to include the name of every needed base workspace entity.
Pruning Unnecessary Names. The cell array neededVars may also include the names of base workspace entities that the protected model does not need. For example, neededVars could contain names of workspace objects that define signals that do not connect to any root I/O port within the protected model. The protected version of the model does not need the corresponding definitions, because they do not specify anything about its interface to other model entities.
Leaving unnecessary names in neededVars risks disclosing intellectual property, adds unnecessary definitions to the receiver's model, and increases the likelihood of a name conflict with that model. Because a protected model cannot be changed, resolving such a conflict would require the receiver's model to change.
To remove unnecessary names, edit the cell array neededVars and delete any names that do not correspond to definitions that serve the protected model in one of the capacities listed under Obtaining Object and Variable Names. If you are not sure which names are extra, you can remove any doubtful cases and later test to see whether any missing definitions result.
Saving Workspace Definitions. The cell array derived in the previous steps contains only the names of base workspace entities. The protected model needs the definitions themselves, in a separate file that can be shipped along with the model. To create this file, execute:
save(myFile.mat, neededVars{:})where myFile is any file (or path) name, and neededVars is the (possibly pruned) second return value of the protect command. The {:} operator converts the cell array neededVars into a list of comma-separated names, which become arguments to save. When the command executes, it evaluates each name, thus obtaining the corresponding definition from the base workspace, and stores all the definitions in myFile.mat. The receiver of the protected model can then restore the base workspace definitions by loading myFile.mat.
A protected model consists of the model itself, optionally a harness model, and any needed definitions saved in a MAT file, as described in Saving Workspace Definitions. The Model Protection facility does not require packaging these files in any specific way. For example, they could be:
Provided as three separate files.
Combined into a ZIP or other container file.
Packaged using a manifest. See Exporting Files in a Manifest.
Provided in some other standard or proprietary format specified by the receiver.
All that matters is that the receiver has the information necessary to access any packing format used and retrieve the original file(s). One way to ensure this result is to use the Simulink Manifest Tools, as described in Model Dependencies.
To test a protected model, you enact the same sequence that the receiver will enact, as described in Using a Protected Model. Since you are also the supplier, both the original and the protected model may exist on the MATLAB path. If a Model block's Model name field names the model without providing a suffix, the unprotected (.mdl) version will take precedence over the protected (.mdlp) model, regardless of their relative positions on the MATLAB path. Explicitly specify the .mdlp suffix in the Model block's Model name field if needed to override this default when testing a protected model.
If you want to ensure that the protected model gives the same results as the source model, you can create a parent model that contains two Model blocks. One Model block references the source model, in Accelerator mode, and the other references the protected model. You can then log the outputs of the blocks and compare the logged data to see that the two versions of the block behave identically. See Logging Signals for more information.
Using a protected model does not require a Real-Time Workshop license. Using a protected model requires that the model:
Be available somewhere on the MATLAB path.
Be referenced by a Model block in a model that executes in Normal mode.
Receive from the Model block the values needed by any defined model arguments.
Connect via the Model block to input and output signals that match those of the protected model.
A typical workflow for meeting these requirements is:
If necessary, unpack the files according to any accompanying directions.
If a MAT-file containing workspace definitions is provided, load the MAT-file.
If a harness model is provided, copy the Model block into a Normal-mode model.
Connect signals to the Model block that match its input and output port requirements.
Provide any needed model argument values. See Assigning Model Argument Values.
You should now be able to simulate the model that references the protected model, which will produce the same outputs that it did when used in Accelerator mode in the source model. Many variations on these instructions are possible, such as:
Use your own Model block rather than the Model block in the harness model.
Start with the harness model, add more constructs to it, and use it in your model.
Use the protected model as a variant, as described in Using Model Reference Variants.
Apply a mask to the Model block that references the protected model. See Working with Block Masks.
Configure a callback function such as LoadFcn to load the MAT file automatically. See Using Callback Functions.
To facilitate locating protected models:
The MATLAB Directory Browser shows a small image of a lock in the upper left corner of a protected model's icon
A Model block that references a protected model shows a small image of a lock in the block's upper left corner.
When the Model block Browse button shows a protected model, the .mdlp suffix and lock icon appear.
When you change a Model block to reference a protected model, the block's Simulation mode becomes Accelerator and cannot be changed.
Protected models are subject to all limitations listed in Limitations on All Model Referencing and Limitations on Accelerator Mode Referenced Models. The following limitations also apply to protected models.
A model that is to be to be protected cannot use a non-inlined S-function directly or indirectly.
Simulating a protected model requires that all models superior to it execute in Normal mode.
Protected models must also meet certain requirements, as described in Model Protection Requirements.
![]() | Using Model Reference Variants | Inheriting Sample Times | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |