MATLAB: How to create a protected model with hidden variables with a mask that provides additional variables

parameterssimulink

How do I create a protected model with hidden variables with a mask that provides additional variables? I want to hide the variables I provide to Simulink that would otherwise appear in the base (MATLAB) workspace.

Best Answer

Before we begin, it should be noted that the protected model must be a referenced model. It cannot be a subsystem. If it is a subsystem, it must be converted to a model reference first. Information about how to do that is at the following link:
Given the original referenced model and a top level model with the model reference block, we perform the following series of steps:
(1) Put hidden and mask parameter variables into the model workspace of the referenced model so that they can no longer appear or be changed from the base workspace. This can be done, for example, by using MATLAB Code as the Data source as shown in the following link:
(2) Specify the model workspace variables that will be provided by the mask as model arguments for the referenced model. This is shown in the following link:
(3) Assign the mask parameter variable names to the model arguments. To do this, in the top level model, right click on the model reference block and go to "Block Parameters (ModelReference)". In the "Model argument values (for this instance)" field and in order, list the names of the mask parameter variables that will correspond with the model workspace variables in "Model arguments". These names will be used to create the mask in step (4). 
(4) Create the mask while setting the names of the mask parameter variables to be the same ones used in "Model argument values (for this instance)" in step (3). An example of how to create a mask, including how to change the mask parameter variable name, can be found at the following link:
If you are creating a mask after protecting a model and need to know what variables it requires, see the following link:
http://www.mathworks.com/help/simulink/examples/protected-models-for-model-reference.html#zmw57dd0e15302
(5) The model can be protected before or after creating a mask. For an example of how to create and use a protected model reference, see below:
 
Related Question