Interpreted Execution vs. Code Generation
You can use MATLAB System block in Simulink® models for simulation via interpreted execution or code generation. Implementing a MATLAB System block with a valid System object™ class name enables the Simulate using parameter. This parameter appears at the bottom of the MATLAB System block dialog if there is only one tab, or the bottom of the first of multiple tabs. Use the Simulate using parameter to control how the block simulates. The table describes how to choose the right value for your purpose.
With interpreted execution, the model simulates the block using the MATLAB® execution engine.
With interpreted execution, if you set the Use division for fixed-point net slope computation parameter to
Use division for reciprocals of integers onlyin the Configuration Parameters dialog box, you might get unoptimized numeric results. These bad numeric results are because MATLAB code does not support this parameter.
With code generation, the model simulates the block using code generation, using the subset of MATLAB code supported for code generation.
Upon first model run, simulate and generate code for MATLAB System using only the subset of MATLAB functions supported for code generation. Choosing this option causes the simulation to run the generated code.
Potentially better performance.
System object is limited to the subset of MATLAB functions supported for code generation. Simulation may start more slowly.
Simulate model using all supported MATLAB functions. Choosing this option can slow simulation performance.
System object can contain any supported MATLAB function. Faster startup time.
Potentially slower performance. If the MATLAB functions in the System object do not support code generation, the System object must contain propagation methods.
To take advantage of faster performance, consider using propagation methods in your System object. For more information, see Add and Implement Propagation Methods.
Simulation Using Code Generation
While simulating and generating code for one or more simulation targets (in this case, System object blocks), the model displays status messages in the bottom left of the Simulink Editor window. A model can have multiple copies of the same MATLAB System block. Blocks are considered the same if they,
Use the same System object.
Have inputs and tunable parameters that have identical signals, data types, and complexities.
Have nontunable parameters that have the same value.
When the model has multiple copies of the same block, the software does not regenerate the code for each block. It reuses the code from the first time that code was generated for one of these blocks. The status messages reflect this and does not show status messages for each of these blocks.
When the code generation process is complete, Simulink creates a MEX-file for the generated code.
- Implement a MATLAB System Block
- Change Blocks Implemented with System Objects
- Change Block Icon and Port Labels
- Add and Implement Propagation Methods
- Use System Objects in Feedback Loops
- Troubleshoot System Objects in Simulink