| Contents | Index |
| On this page… |
|---|
A protected model is a referenced model that eliminates all block and line information. Protecting a model does not use encryption technology. You can distribute a protected model 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 contents of the model are hidden. For example, the Model Explorer and the Model Dependency Viewer show the hierarchy under an ordinary referenced model, but not under a protected model. You cannot log signals in a protected model, because the log could reveal information about the protected model contents.
Some referenced model require object definitions or tunable parameters that are defined in the MATLAB base workspace. For those models, the protected version may need some 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 Simulink Coder 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 Simulink Coder license to use the model. Also, a third party cannot use Simulink Coder 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 mode
Identify definitions that it needs
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 Help browser and choose Simulink > Demos > Modeling Features > Model Reference > Model Reference Protected Models
Protecting a model requires meeting all requirements listed in Simulink Model Referencing Requirements, as well as the following:
You must have a Simulink Coder license, which you can obtain via http://www.mathworks.com.
Your platform and your version of Simulink must match the platform and version of Simulink that the protected model uses.
The model that you protect must be available on the MATLAB path and have no unsaved changes.
The model that you protect cannot reference any subordinate protected model directly or indirectly.
Model protection is also subject to certain limitations, as described in Model Protection Limitations.
You can create a protected model using either:
The Simulink.ModelReference.protect command
The Model block context menu (see Creating a Protected Model Using the Model Block Context Menu)
The command-line interface allows you to:
Specify the path for the protected model (The Model block interface creates the protected model in the current folder.)
Choose whether to generate a test harness (The Model block interface automatically generates a test harness.) For details about the generated test harness, see The Harness Model.
When you create a protected model:
By default Simulink creates a protected version of the referenced model and stores the protected version in the current working folder. The protected model has the same name as the source model, with the suffix .mdlp.
In the Library Browser, a small image of a lock appears in the upper-left corner of the icon for a protected model.
If the Model block uses variants, only the active variant is protected. For more information, see Modeling Variant Systems.
You can use the Simulink.ModelReference.protect command create a protected model.
To create only a protected model, with no harness model or list of names, specify the source model to the protect command:
Simulink.ModelReference.protect(model)
To specify a folder other than the current working folder 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 folder.
To create a harness model when you protect 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)For details about the generated test harness, see The Harness Model.
In the Simulink Editor, right-click the Model block that references the model for which you want to generate protected model code.
On the context menu, select Code Generation > Generate Protected Model.
When you choose the Generate Protected Model menu item, Simulink:
Leaves the original model unchanged
Creates a protected model version of the referenced model in the current working folder
Creates a harness model in the current working folder (for details, see The Harness Model)
If you use the Simulink.ModelReference.protect command to create a protected model, you can choose whether to create a harness model. If you use the Model block interface to create a protected model, Simulink automatically creates a harness model.
The harness model contains a Model block that works 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
The harness model opens as a new untitled model that contains only the 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.
Some ways to use the harness model include:
Save the harness model 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.
Some referenced models require objects or tunable parameters that are defined in the MATLAB base workspace. Executing the protected version of such a referenced model requires that same entity if it is:
A global tunable parameter
A global data store
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.
When the protect command executes, it always generates a cell array that includes the names of all base workspace entities that the protected model needs. 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 includes the name of every needed base workspace entity.
The cell array neededVars might 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 the definitions 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 model of the receiver
Increases the likelihood of a name conflict with that model
Because you cannot change a protected model, resolving such a conflict requires changing the model of the receiver.
To remove unnecessary names, edit the cell array neededVars. 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 for a Protected Model. 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.
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 you can ship 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, you could use one of the following approaches to package the files:
Providing them as three separate files
Combining them into a ZIP or other container file
Packaging them using a manifest (see Export Files in a Manifest)
Providing them in some other standard or proprietary format specified by the receiver
Whichever approach you use to package a protected model, be sure the receiver of the package has the information necessary retrieve the original files. One approach to consider is to use the Simulink Manifest Tools, as described in Model Dependencies.
To test a protected model, use the same sequence that the protected model receiver will use, as described in Using a Protected Model. Because you are also the supplier, both the original and the protected model might exist on the MATLAB path. If the Model name field of a Model block names the model without providing a suffix, the unprotected version takes precedence over the protected model. This occurs regardless of the relative positions of the versions on the MATLAB path. If you need to override this default when testing a protected model, then in the Model block Model name parameter, explicitly specify the file name with the extension of the protected model.
To compare unprotected and protected versions of a model, use the Simulation Data Inspector.
For the unprotected model, select the Configuration Parameters > Data Import/Export > Record and inspect simulation output parameter.
Simulate the unprotected model.
When the simulation completes, the Simulation Data Inspector opens.
In the Simulation Data Inspector, rename the run to indicate that it is for the unprotected model.
Close the unprotected model.
Make sure that the protected model is in a different folder than the folder that contains the unprotected model.
For the protected model, select the Configuration Parameters > Data Import/Export > Record and inspect simulation output parameter.
Simulate the protected model.
When the simulation completes, the Simulation Data Inspector opens.
In the Simulation Data Inspector, rename the run to indicate that it is for the protected model.
In the Simulation Data Inspector, select the Compare Runs tab to compare the runs for the unprotected and the protected model. For details, see Comparison of All Logged Signal Data From Multiple Simulations.
For more information about using the Simulation Data Inspector, see Inspecting and Comparing Logged Signal Data.
Using a protected model does not require a Simulink Coder 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
Receives from the Model block the values needed by any defined model arguments
Connects via the Model block to input and output signals that match the input and output signals of the protected model
A typical workflow for meeting these requirements is:
If necessary, unpack the files according to any accompanying directions.
If there is a MAT-file containing workspace definitions, load that MAT-file.
If there is a harness model, 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.
Now you can simulate the model that references the protected model. The simulation produces 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 Modeling Variant Systems.
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 Folder Browser shows a small image of a lock in the upper left corner of the icon of a protected model.
A Model block that references a protected model shows a small image of a lock in the upper left corner of the block icon.
When the Model block Browse button shows a protected model, a lock icon appears.
When you change a Model block to reference a protected model, the Simulation mode of the block becomes Accelerator and you cannot change it.
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 you protect 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.
![]() | Conditional Referenced Models | Inheriting Sample Times | ![]() |

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