Skip to Main Content Skip to Search
Product Documentation

Protecting Referenced Models

About Protected Models

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

The Model Protection facility is a set of Simulink commands, tools, and techniques that you can use to:

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

Model Protection Requirements

Protecting a model requires meeting all requirements listed in Simulink Model Referencing Requirements, as well as the following:

Model protection is also subject to certain limitations, as described in Model Protection Limitations.

Creating a Protected Model

You can create a protected model using either:

The command-line interface allows you to:

When you create a protected model:

Creating a Protected Model Using the Simulink.ModelReference.protect Command

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.

Creating a Protected Model Using the Model Block Context Menu

  1. In the Simulink Editor, right-click the Model block that references the model for which you want to generate protected model code.

  2. On the context menu, select Code Generation > Generate Protected Model.

When you choose the Generate Protected Model menu item, Simulink:

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:

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:

See Packaging a Protected Model for more about how to use a harness model and the Model block that it contains.

Obtaining Object and Variable Names for a Protected Model

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:

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:

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

Pruning Unnecessary Names

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:

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.

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

Packaging a Protected Model

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:

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.

Testing a Protected Model

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.

  1. For the unprotected model, select the Configuration Parameters > Data Import/Export > Record and inspect simulation output parameter.

  2. Simulate the unprotected model.

    When the simulation completes, the Simulation Data Inspector opens.

  3. In the Simulation Data Inspector, rename the run to indicate that it is for the unprotected model.

  4. Close the unprotected model.

  5. Make sure that the protected model is in a different folder than the folder that contains the unprotected model.

  6. For the protected model, select the Configuration Parameters > Data Import/Export > Record and inspect simulation output parameter.

  7. Simulate the protected model.

    When the simulation completes, the Simulation Data Inspector opens.

  8. In the Simulation Data Inspector, rename the run to indicate that it is for the protected model.

  9. 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

Using a protected model does not require a Simulink Coder license. Using a protected model requires that the model:

A typical workflow for meeting these requirements is:

  1. If necessary, unpack the files according to any accompanying directions.

  2. If there is a MAT-file containing workspace definitions, load that MAT-file.

  3. If there is a harness model, copy the Model block into a Normal-mode model.

  4. Connect signals to the Model block that match its input and output port requirements.

  5. 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:

To facilitate locating protected models:

When you change a Model block to reference a protected model, the Simulation mode of the block becomes Accelerator and you cannot change it.

Model Protection Limitations

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:

Protected models must also meet certain requirements, as described in Model Protection Requirements.

  


Related Products & Applications

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