Main Content

Simulation Modes

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 On or Use division for reciprocals of integers only in 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.

Code generation (default)

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.

Interpreted execution

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.


If a Simulink model is setup to simulate in Normal mode and if you use MATLAB System block via code generation individual MATLAB System blocks can take advantage of the acceleration via code generation. If the Simulink model is setup to simulate in accelerator or any of the other target modes, MATLAB System block's Simulate using parameter does not have any effect. There is only one exception. If the model is setup to simulate in Accelerator mode and you use MATLAB System block with interpreted execution mode, the block will run in interpreted execution mode.

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.

See Also

Related Examples

More About