Main Content

Simulink.ProtectedModel.addTarget

Add code generation support for current target to protected model

Description

Simulink.ProtectedModel.addTarget(mdl) adds code generation support for the target of the current model, specified by mdl, to a protected model of the same name. Each target that the protected model supports is identified by the root of the System target file configuration 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.

example

Simulink.ProtectedModel.addTarget(mdl,Verbose=tf) lets you specify whether to display verbose build process information during model protection. (since R2024b)

example

Examples

collapse all

Add the currently configured model target to the protected model.

Load an example model.

mdl = "sldemo_mdlref_counter";
openExample(mdl);

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(...
mdl,"password");

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

Simulink.ModelReference.protect(mdl,Mode="CodeGeneration",...
Modifiable=true,Report=true);

Get a list of targets that the protected model supports.

 st = Simulink.ProtectedModel.getSupportedTargets(mdl)

Configure the unprotected model to support a new target.

 set_param(mdl,SystemTargetFile="ert.tlc"); 
 save_system(mdl);

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

 Simulink.ProtectedModel.addTarget(mdl);

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

 st = Simulink.ProtectedModel.getSupportedTargets(mdl)

Add the currently configured model target to the protected model.

Load an example model.

mdl = "sldemo_mdlref_counter";
openExample(mdl);

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(...
mdl,"password");

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

Simulink.ModelReference.protect(mdl,Mode="CodeGeneration",...
Modifiable=true,Report=true,Verbose=true);

Get a list of targets that the protected model supports.

 st = Simulink.ProtectedModel.getSupportedTargets(mdl)

Configure the unprotected model to support a new target.

 set_param(mdl,SystemTargetFile="ert.tlc"); 
 save_system(mdl);

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

 Simulink.ProtectedModel.addTarget(mdl,Verbose=true);

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

 st = Simulink.ProtectedModel.getSupportedTargets(mdl)

Input Arguments

collapse all

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

Since R2024b

Verbose output of build process information, specified as a numeric or logical 0 (false) or 1 (true).

By default, the model protection process displays limited build process information. To display verbose build process information during model protection, set Verbose to true.

To control the display of build process information, the model protection process temporarily overrides the values of the Verbose accelerator builds and Verbose build configuration parameters.

Data Types: logical

Version History

Introduced in R2015a

expand all