This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Protected Models for Model Reference

This example shows how to create and use a protected model in Normal and Accelerated mode simulations, as well as for code generation.

Example Requirements

Before you can generate protected models, you must have Simulink® Coder™ installed. To generate the read-only view of protected models, you must have Simulink® Report Generator™ installed.

Open the Example Model

Open the example model, sldemo_mdlref_bus.

Figure 1: The example model, sldemo_mdlref_bus

Protect the Referenced Model

This model contains one Model block, CounterA. To protect the model referenced by this block, right-click the Model block and select Subsystem & Model Reference > Create Protected Model for Selected Model Block. A dialog box opens where you can select options for creating a protected model.

Figure 2: Protected model dialog box

Under Allow user of protected model to select Open read-only view of model, Simulate, and Generate code. You have the option of entering passwords for the 3 aforementioned functionalities. The 3 passwords are used to protect the respective functionalities.Enter separate passwords for the 3 options and click Create. A protected model file, sldemo_mdlref_counter_bus.slxp, is generated in the current working folder. You can use this protected model in Normal and Accelerated mode simulations, as well as for code generation. You can also open a read-only view of the model. The original model file is not required.

Determine the Variables for a Protected Model

To simulate a model that references a protected model, you might need to define variables in the base workspace. For example, the protected model, sldemo_mdlref_counter_bus, needs the base workspace variables that specify the buses at the root input and output ports of the model. When you ship a protected model, you must include definitions of the required variables or the model is unusable. The protect command generates a protected model and determines the required variables. For example:

[~, neededVars] = Simulink.ModelReference.protect('sldemo_mdlref_counter_bus', 'Mode', 'CodeGeneration', 'OutputFormat', 'MinimalCode', 'ObfuscateCode', true, 'Harness', true, 'Report', true, 'Webview', true)

The second output of the protect function, neededVars, includes base workspace variables you must send to the recipient. The value of neededVars is a cell array that contains the names of the base workspace variables required for the protected model. However, the cell array might also contain the names of workspace variables that the model does not need.

Before you share a protected model, edit neededVars to delete the names of any variables that the model does not need. Save the required workspace variables into a MAT-file:

save('sldemo_mdlref_counter_bus_vars', neededVars{:});

Use the Protected Model

When the Model block references a protected model, a shield badge is displayed on the block.

Figure 3: Referencing a protected model

Right-click on the shield badge and select Authorize.... Enter the passwords you used while creating the protected model.

Figure 4: Password entry dialog

Now you can simulate the model in either Normal or Accelerator mode. You can also build the top model by selecting Code > C/C++ Code > Build Model.

Double-click the Model block to open the read-only view of the model. Alternatively, right-click on the shield badge and select Show Webview to open the read-only view of the model.

Figure 5: The protected model web view

Right-click on the shield badge and select Display Report to open the report

Figure 6: The protected model report

Was this topic helpful?