How can I protect a Simscape model?
    27 views (last 30 days)
  
       Show older comments
    
    MathWorks Support Team
    
 on 14 Sep 2018
  
    
    
    
    
    Edited: MathWorks Support Team
    
 on 28 Oct 2025 at 10:58
            I have a simple Simscape model which has connection ports exposed out of it. I tried two ways to protect the Simscape model:
First, I tried to generate an S-function from it. I got the following error:
The selected system expresses connection ports. Subsystem based code generation is not supported for portions of physical models.  In order to generate code, the physical model must exist entirely within a subsystem.
Two, if I instead try to generate a protected model, I get a model reference with missing connection ports.
How can I protect my Simscape model? 
Accepted Answer
  MathWorks Support Team
    
 on 28 Oct 2025 at 0:00
        
      Edited: MathWorks Support Team
    
 on 28 Oct 2025 at 10:58
  
      There are two types of references, a Model Reference and a Subsystem Reference. Subsystem references can contain physical connection ports that are used in a Simscape model as its input and output ports. However, you cannot protect a subsystem reference block using the Model Protection workflow. Whereas, model references cannot contain physical connections as input and output ports. Additionally, conversion of models or subsystems containing Simscape blocks to S-functions is not supported as per the limitations. 
There are a couple of workarounds we can use to protect Simscape models despite the above limitations: 
1) You can automatically convert subsystems containing only Simscape components into an SSC file using the 'subsystem2ssc' function. After that, you can use 'sscprotect' to create a protected Simscape source code file of extension SSCP. Just like with unprotected source files, you can build custom block libraries from SSCP files using the 'sscbuild' command. Visit the documentation page on protecting simscape files to learn more. 
2) If your physical network includes specific input and output parameters, such as actuation commands or sensor outputs, consider transforming the model to use only Simulink interfaces. You can achieve this by utilizing PS-Simulink and Simulink-PS converters along with Simulink-based Inport/Outport blocks. This approach creates a self-contained physical network, enabling you to utilize protected model references. 
0 Comments
More Answers (0)
See Also
Categories
				Find more on Foundation and Custom Domains in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!