Main Content

Simulink.ProtectedModel.addTarget

Add code generation support for current target to protected model

Description

example

Simulink.ProtectedModel.addTarget(model) adds code generation support for the current model target to a protected model of the same name. Each target that the protected model supports is identified by the root of the Code Generation > System Target file (SystemTargetFile) parameter. For example, if the System Target file is ert.tlc, the target identifier is ert.

To add the current target:

  • The model and the protected model of the same name must be on the MATLAB® path.

  • The protected model must have the Modifiable option enabled and have a password for modification.

  • The target must be unique in the protected model.

If you add a target to a protected model that did not previously support code generation, the software switches the protected model Mode to CodeGeneration and ObfuscateCode to true.

Examples

collapse all

Add the currently configured model target to the protected model.

Load the model and save a local copy.

openExample('sldemo_mdlref_counter');
save_system('sldemo_mdlref_counter','mdlref_counter.slx');

Add a required password for modifying a protected model. If you do not add a password, you are prompted to set a password when you create a modifiable, protected model.

Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'mdlref_counter','password');

Create a modifiable, protected model with support for code generation.

Simulink.ModelReference.protect('mdlref_counter','Mode',...
'CodeGeneration', 'Modifiable',true, 'Report',true);

Get a list of targets that the protected model supports.

 st = Simulink.ProtectedModel.getSupportedTargets('mdlref_counter')

Configure the unprotected model to support a new target.

 set_param('mdlref_counter', 'SystemTargetFile', 'ert.tlc'); 
 save_system('mdlref_counter');

Add support to the protected model for the new target. You are prompted for the modification password.

 Simulink.ProtectedModel.addTarget('mdlref_counter');

Verify that support for the new target has been added to the protected model.

 st = Simulink.ProtectedModel.getSupportedTargets('mdlref_counter')

Input Arguments

collapse all

Model name, specified as a string or character vector. It contains the name of a model or the path name of a Model block that references the protected model.

Introduced in R2015a