Choose Tools to Integrate Existing Components and MATLAB, C/C++, or Python Code into Simulink
Simulink® provides a wide range of tools to help you integrate your existing components and code from various sources into Simulink to create large-scale models. You can integrate your native Simulink components, components authored using third-party tools, and your MATLAB®, C/C++, or Python code into Simulink.
This topic helps you select the appropriate tool for creating your large-scale model components based on your modeling requirements and code constructs.
The first section provides recommendations for integration tools that account for most of the common modeling requirements.
The second section provides more detailed information regarding additional considerations and recommendations for choosing integration tools for advanced configurations.
If you choose to develop your component from the ground up instead of integrating an existing behavior, you can use block and blockset authoring tools provided by Simulink, see Choose Tools to Create Reusable Blocks in Simulink Using C/C++ or MATLAB.
Choose Component and Code Integration Tools For Most Common Requirements
For most of your integration workflows, here are the three major considerations. To integrate:
Native simulink components, use subsystems, model reference, subsystem reference based on your modeling requirements, for more information see Explore Types of Model Components.
Components authored using third-party tools, use FMU or S-Function as co-simulation gateway. For more information, see Implement an FMU Block and Third-Party Functionality Integration.
Code by importing it into Simulink, use:
MATLAB Function block if your code is written in MATLAB.
Python Importer if you code written in Python. For more information, see Import Python Code to Simulink Using Python Importer Wizard.
C Function block if your code is written in C/C++.
Integrate C/C++ Code with Advanced Configurations
When you import and integrate C/C++ code into Simulink, you may need to consider more advanced configurations such as the states or your code constructs.
If you model state dynamics, first consider whether you need to generate inline code without writing your own TLC. For more information about inlined S-function and writing a TLC, see Inlining S-Functions (Embedded Coder).
Use S-Function Builder if you want to generate inline code for your component without writing your own TLC. S-Function Builder is designed for ease of use, providing you with a graphical user interface and editor. It implements a fixed set of Simulink callbacks to enable interaction with the Simulink engine and implementation of continuous and discrete state dynamics. S-Function Builder also generates a TLC as part of its build process. This allows you to generate inline code during code generation of a model containing the S-Function Builder without having to write a TLC yourself. For more information on using S-Function Builder, see Build S-Functions Automatically Using S-Function Builder.
Use C MEX S-Function if your component requires advanced configurations that are beyond the scope of the fixed set of Simulink callbacks provided in the S-Function Builder. For more information on creating a C MEX S-function, see Create and Implement a Basic C MEX S-Function.
Another consideration is the code constructs. If you integrate methods from C++ classes, or functions written in C language that require conditional data execution or multiple functions in a single block implementation, use the C Function block. If you integrate functions in C language without further requirements, use the C Caller block.
See Also
Choose Tools to Create Reusable Blocks in Simulink Using C/C++ or MATLAB