In Simulink, the use of protected models through a password allows the model's accessibility to be restricted by the user for view, modification, simulation or code generation.
Simulink supports a feature for which the password can be introduced programmatically. This allows having a separate "unlocking script", that would write down the password in the model when certain conditions are met (such as date and username).
In order to protect the password in the script, this can be p-coded, which will provide an encrypted p-file that can be shared with the users that will access the model, similar to a key to open the model.
As an example, consider the case in which a user would like to protect their model from view by other users. They could use the function
to set the password for their protected model and to create an unlocking script that will be p-coded.
In order to programmatically set up the password in the model:
Simulink.ModelReference.ProtectedModel.setPasswordForView(...
'protected_model_ref','password');
Simulink.ModelReference.protect('protected_model_ref',...
'Webview',true,'Encrypt',true,'Report',true);
As for the script to unlock the model, it can contain an "i"f statement to check for certain conditions, and the write the password accordingly:
Simulink.ModelReference.ProtectedModel.setPasswordForView(...
'protected_model_ref','password');
A similar workflow can be followed in order to protect the model from modification, simulation
After having used the file to set the password, the unlocking script can be p-coded and distributed to users. They can then use this file to unlock the model.
Best Answer