Create Simscape protected or pre-compiled model for users who don't have Simscape licenses

62 views (last 30 days)
I created a Simulink model (Model.slx) containing Simscape blocs. I need to share with some people for compilation purposes who does not have Simscape licenses.
I could create a script to protect the Simulink model:
Simulink.ModelReference.protect('Model.slx', ...
'Path', 'C:\MyFolder', ...
'Report', true, ...
'Mode', 'CodeGeneration', ...
'CodeInterface', 'Top model', ...
'OutputFormat', 'CompiledBinaries');
On my laptop with Simscape licenses, I am able to compile the Simulink (CodeToCompile.slx) that contains the protected model, and the code works as expected. But people who does not have Simscape licenses are not able to compile the code. I tried to compile the Simulink model into C code, but that created mainy .c files, so I am not confident in how to import the compiled model into CodeToCompile.slx.
Am I missing an option into the Simulink.ModelReference.protect function ? Should I go with the generated C code, and add each .c and .h to the Custom Codes of CodeToCompile.slx ? Are there any other way to create a model from Model.slx that people who don't have Simscape licences can compile ?
Many thanks for your help !

Answers (2)

Ayush
Ayush on 1 Sep 2025 at 9:23
Hi, Valentin,
I understand you want to share a Simulink model containing Simscape blocks with colleagues who do not have a Simscape license. I see you have tried compiling the Simulink model into C code but encountered difficulties managing all the generated .c and .h files.
Here are the ways to share a pre-compiled model:
  • Create a protected Simulink model to share it:
  1. Open your model in Simulink.
  2. Under the “Simulation” tab, click the “Save” dropdown and select “Protected Model”. You can generally leave the default settings.
  3. This model can now be used as a referenced model by your colleague.
  • Create an executable of your Simulink model:
  1. Open your model in Simulink
  2. Under the “Modelling” tab, go to “Model Settings” > “Code Generation”. Set “System Target File” to “grt.tlc” and leave "Generate code only" unchecked.
  3. Ensure the solver type is set to “Fixed-step” type.
  4. Confirm you have Simulink coder license and go to “Apps” > “Simulink Coder”and then click on “Build”.
  5. An executable file (“CodetoCompile.exe”) will be generated.
You can refer this answer posted by MathWorks staff on similar issue:
Helpful Documentation:
2) For Simulink coder: Simulink Coder Documentation
Hope this helps clarify your options.
  1 Comment
Valentin
Valentin on 2 Sep 2025 at 7:10
Hi Ayush,
Thank you for your reply !
I have already seen that discussion that looks like very close to my topic. As I said I already tried protected model. With the default settings, the protected model is dedicated for simulation. But people I need to share the model with (no Simscape license for them) are looking to compile the whole code that will include the model. Here is a scheme describing maybe better what I am looking for:
Instead of using the UI window to generate the protected model, I used the script I have given in my original question. I could change the protected model settings for code generation, I am now able to compile the CodeToCompile.slx, but people who don't have Simscape licenses they still can't. I may use wrong settings.
The other solution, compiling the Simscape model to an executable, could be interesting for non-Simscape users. But tell me if I am wrong, they could not import the .exe into the Simulink they would like to compile, and interact with inputs/outputs. They will ?
Hope it is more clear for you to understand what I am looking for, and make it easier to find a solution.
Valentin

Sign in to comment.


Yifeng Tang
Yifeng Tang on 3 Sep 2025 at 18:33
I don't think Model reference, protected or not, will allow the user to run without Simscape.
Do you have the licenses needed to create a standalone FMU? You can bring that into a Simulink for a non-Simscape user, and that won't require Simscape license.

Categories

Find more on Configure and View Diagnostics in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!