Blocks and Products Supported for Code Generation

As you construct a model, to prevent issues later in the development process, determine whether the Simulink® Coder™ and Embedded Coder® code generators support the products and blocks that you want to use.

Related Products

The following table summarizes MathWorks® products that extend and complement Simulink Coder software. For information about these products and how code generation supports them, refer to their product documentation at www.mathworks.com.

ProductExtends Code Generation Capabilities for ...

Aerospace Blockset™

Aircraft, spacecraft, rocket, propulsion systems, and unmanned airborne vehicles

Audio Toolbox™

Audio processing systems
Automated Driving Toolbox™ Designing, simulating, and testing ADAS and autonomous driving systems
AUTOSAR Blockset Modeling and simulation of AUTOSAR Classic and Adaptive ECU software

Communications Toolbox™

Physical layer of communication systems

Computer Vision Toolbox™

Video processing, image processing, and computer vision systems

Control System Toolbox™

Linear control systems

DSP System Toolbox™

Signal processing systems
Embedded Coder Embedded systems, rapid prototyping boards, and microprocessors in mass production

Fixed-Point Designer™

Fixed-point systems

Fuzzy Logic Toolbox™

System designs based on fuzzy logic
HDL Verifier™

Direct programming interface (DPI) component and transaction-level model (TLM) generation from Simulink

IEC Certification Kit

ISO 26262 and IEC 61508 certification

Model-Based Calibration Toolbox™

Developing processes for systematically identifying optimal balance of engine performance, emissions, and fuel economy, and reusing statistical models for control design, hardware-in-the-loop (HIL) testing, or powertrain simulation

Model Predictive Control Toolbox™

Model predictive controllers
Deep Learning Toolbox™ Neural networks
Parallel Computing Toolbox™ Parallel builds for large Simulink models
Phased Array System Toolbox™ Sensor array systems in radar, sonar, wireless communications, and medical imaging applications
Polyspace® Bug Finder™

MISRA-C compliance and static analysis of generated code

Polyspace Code Prover™

Formal analysis of generated code

Powertrain Blockset™

Real-time testing of powertrain applications

Robotics System Toolbox™

Design, simulate, and test robotics applications

ROS Toolbox

Design, simulate, and deploy ROS-based applications

Simscape™

Systems spanning mechanical, electrical, hydraulic, and other physical domains as physical networks

Simscape Driveline™

Driveline (drivetrain) systems
Simscape Electrical™ Electronic, electromechanical, and electrical power systems

Simscape Fluids™

Hydraulic power and control systems

Simscape Multibody™

Three-dimensional mechanical systems

Simulink 3D Animation™

Systems with 3D visualizations
Simulink Check™ Model standards compliance checking and metrics
Simulink Code Inspector™

Automated reviews of generated code

Simulink Control Design™ Autotuning of PID controllers and online frequency response estimation
Simulink Coverage™ Model and code structural coverage analysis

Simulink Design Optimization™

Tuning adaptive lookup tables and checking signal characteristics

Simulink Desktop Real-Time™

Rapid prototyping or hardware-in-the-loop (HIL) simulation of control system and signal processing algorithms

Simulink Real-Time™

Rapid control prototyping, hardware-in-the-loop (HIL) simulation, and other real-time testing applications

Simulink Report Generator™

Automatically generating project documentation in a standard format
Simulink Requirements™ Authoring and tracing requirements to design and code
Simulink Test™

Software-in-the-loop (SIL), processor-in-the-loop (PIL), and real-time hardware-in-the-loop (HIL) testing of generated code

SoC Blockset™ Designing, evaluating, and implementing SoC hardware and software architectures
Stateflow® State machines and flow charts

System Identification Toolbox™

Systems identified from measured input-output data
Vehicle Dynamics Blockset™ Modeling and simulation of vehicle dynamics in 3D environment

Vehicle Network Toolbox™

CAN blocks for Accelerator and Rapid Accelerator simulations and code deployment on Windows®

Simulink Built-In Blocks That Support Code Generation

The following tables summarize code generator support for Simulink blocks. There is a table for each block library. For more detail, including data types each block supports, in the MATLAB® Command Window, type showblockdatatypetable, or consult the block reference pages. For some blocks, the generated code might rely on memcpy or memset (string.h).

Additional Math and Discrete: Additional Discrete

BlockSupport Notes
Fixed-Point State-Space

The code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.

Transfer Fcn Direct Form II
Transfer Fcn Direct Form II Time Varying

Additional Math and Discrete: Increment/Decrement

BlockSupport Notes
Decrement Real WorldThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Decrement Stored Integer
Decrement Time To ZeroSupports code generation.
Decrement To ZeroThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Increment Real World
Increment Stored Integer

Continuous

BlockSupport Notes
Derivative

Not recommended for production-quality code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. The code generated can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code.

In general, consider using the Simulink Model Discretizer to map continuous blocks into discrete equivalents that support production code generation. Use the Model Discretizer app. One exception is the Second-Order Integrator block because, for this block, the Model Discretizer produces an approximate discretization.

Integrator
Integrator, Integrator Limited
PID Controller
PID Controller (2DOF)
Second-Order Integrator, Second-Order Integrator Limited
State-Space
Transfer Fcn
Transport Delay
Variable Time Delay, Variable Transport Delay
Zero-Pole

Discontinuities

BlockSupport Notes
BacklashSupports code generation.
Coulomb and Viscous FrictionThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Dead ZoneSupports code generation.
Dead Zone DynamicThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Hit CrossingNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
QuantizerSupports code generation.
Rate LimiterCannot use inside a triggered subsystem hierarchy.
Rate Limiter DynamicThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
RelaySupport code generation.
Saturation
Saturation DynamicThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Wrap To Zero

Discrete

BlockSupport Notes
DelaySupports code generation.
Difference
  • The code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.

  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Discrete Derivative
  • Depends on absolute time when used inside a triggered subsystem hierarchy.

  • Supports code generation.

Discrete FilterSupport code generation.
Discrete FIR Filter
Discrete PID Controller
  • Depends on absolute time when used inside a triggered subsystem hierarchy.

  • Support code generation.

Discrete PID Controller (2DOF)
Discrete State-SpaceSupport code generation.
Discrete Transfer Fcn
Discrete Zero-Pole
Discrete-Time IntegratorDepends on absolute time when used inside a triggered subsystem hierarchy.
Enabled DelaySupports code generation.
First Order HoldNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
MemorySupport code generation.
Resettable Delay
Tapped Delay
Transfer Fcn First OrderThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Transfer Fcn Lead or Lag
Transfer Fcn Real Zero
Unit DelaySupport code generation.
Variable Integer Delay
Zero-Order Hold

Lookup Tables

BlockSupport Notes
CosineThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting the Treat as atomic unit check box.
Direct Lookup Table (n-D)Support code generation.
Interpolation Using Prelookup
1-D Lookup Table
2-D Lookup Table
n-D Lookup Table
Lookup Table Dynamic
Prelookup
SineThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.

Math Operations

BlockSupport Notes
AbsSupport code generation.
Add
Algebraic Constraint Ignored during code generation.
AssignmentSupport code generation.
Bias
Complex to Magnitude-Angle
Complex to Real-Imag
Divide
Dot Product
Find Nonzero Elements
Gain
Magnitude-Angle to Complex
Math Function (10^u)
Math Function (conj)
Math Function (exp)
Math Function (hermitian)
Math Function (hypot)
Math Function (log)
Math Function (log10)
Math Function (magnitude^2)
Math Function (mod)
Math Function (pow)
Math Function (reciprocal)
Math Function (rem)
Math Function (square)
Math Function (transpose)
Vector Concatenate, Matrix Concatenate
MinMax
MinMax Running Resettable
Permute Dimensions
Polynomial
Product
Product of Elements
Real-Imag to Complex
Sqrt, Signed Sqrt, Reciprocal Sqrt
Reshape
Rounding Function
Sign
Sqrt, Signed Sqrt, Reciprocal Sqrt
Sine Wave Function
  • Does not refer to absolute time when configured for sample-based operation. Depends on absolute time when in time-based operation.

  • Depends on absolute time when used inside a triggered subsystem hierarchy.

Slider GainSupport code generation.
Sqrt
Squeeze
Subtract
Sum
Sum of Elements
Trigonometric FunctionFunctions asinh, acosh, and atanh are not supported by all compilers. If you use a compiler that does not support those functions, the software issues a warning for the block and the generated code fails to link.
Unary MinusSupport code generation.modeling Gui
Vector Concatenate, Matrix Concatenate
Weighted Sample Time Math

Model Verification

BlockSupport Notes
AssertionSupports code generation.
Check Discrete Gradient

Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Check Dynamic GapSupport code generation.
Check Dynamic Lower Bound
Check Dynamic Range
Check Dynamic Upper Bound
Check Input ResolutionNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Check Static Gap
Check Static Lower Bound
Check Static Range
Check Static Upper Bound

Model-Wide Utilities

BlockSupport Notes
Block Support TableIgnored during code generation.
DocBlockUses the template symbol you specify for the Embedded Coder Flag block parameter to add comments to generated code. Requires an Embedded Coder license. For more information, see Use a Simulink DocBlock to Add a Comment.
Model InfoIgnored during code generation.
Timed-Based Linearization
Trigger-Based Linearization

Signal Attributes

BlockSupport Notes
Bus to VectorSupport code generation.
Data Type Conversion
Data Type Conversion Inherited
Data Type Duplicate
Data Type Propagation
Data Type Scaling Strip
ICNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
ProbeSupports code generation.
Rate Transition
  • Supports code generation.

  • Cannot use inside a triggered subsystem hierarchy.

Signal ConversionSupport code generation.
Signal Specification
Unit Conversion
Weighted Sample Time
Width

Signal Routing

BlockSupport Notes
Bus AssignmentSupport code generation.
Bus Creator
Bus Selector
Data Store Memory
Data Store Read
Data Store Write
Demux
Environment ControllerNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
FromSupport code generation.
Goto
Goto Tag Visibility
Index Vector
Manual SwitchNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Manual Variant SinkSupport code generation.
Manual Variant Source
MergeWhen multiple signals connected to a Merge block have a non-Auto storage class, all non-Auto signals connected to that block must be identically labeled and have the same storage class. When Merge blocks connect directly to one another, these rules apply to all signals connected to Merge blocks in the group.
Multiport SwitchSupport code generation.
Mux
Selector
State Reader
State Writer
Switch
Variant Sink
Variant Source
Vector Concatenate

Sinks

BlockSupport Notes
DisplayIgnored for code generation.
Floating Scope and Scope Viewer
Outport (Out1)Supports code generation.
ScopeIgnored for code generation.
Stop Simulation
  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

  • Generated code stops executing when the stop condition is true.

TerminatorSupports code generation.
To FileNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
To WorkspaceIgnored for code generation.
XY Graph

Sources

BlockSupport Notes
Band-Limited White NoiseCannot use inside a triggered subsystem hierarchy.
Chirp SignalNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Clock
ConstantSupports code generation.
Counter Free-RunningNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Counter Limited
  • The code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.

  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

Digital ClockNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Enumerated ConstantSupports code generation.
From FileNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
From Spreadsheet
From WorkspaceIgnored for code generation.
GroundSupport code generation.
Inport (In1)
Pulse GeneratorCannot use inside a triggered subsystem hierarchy. Does not refer to absolute time when configured for sample-based operation. Depends on absolute time when in time-based operation.
RampNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Random NumberSupports code generation.
Repeating Sequence
  • Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

  • Consider using the Repeating Sequence Stair or Repeating Sequence Interpolated block instead.

Repeating Sequence Interpolated
  • The code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.

  • Cannot use inside a triggered subsystem hierarchy.

Repeating Sequence StairThe code generator does not explicitly group primitive blocks that constitute a nonatomic masked subsystem block in the generated code. This flexibility allows for more efficient code generation. In certain cases, you can achieve grouping by configuring the masked subsystem block to execute as an atomic unit by selecting block parameter Treat as atomic unit.
Signal BuilderNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Signal Generator
Sine Wave
  • Depends on absolute time when used inside a triggered subsystem hierarchy.

  • Does not refer to absolute time when configured for sample-based operation. Depends on absolute time when in time-based operation.

StepNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Uniform Random NumberSupports code generation.
Waveform GeneratorNot recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.

User-Defined

BlockSupport Notes
Function CallerSupport code generation.
Initialize Function
Interpreted MATLAB FunctionConsider using the MATLAB Function block instead.
Level-2 MATLAB S-FunctionIf a corresponding TLC file is available, the Level-2 MATLAB S-Function block uses the TLC file to generate code, otherwise code generation throws an error.
MATLAB FunctionSupport code generation.
MATLAB System
S-FunctionS-functions that call into MATLAB are not supported for code generation.
S-Function Builder
Simulink FunctionSupport code generation.
Terminate Function

Simulink Block Data Type Support Table

The Simulink Block Data Type Support table summarizes characteristics of blocks in the Simulink and Fixed-Point Designer block libraries, including whether or not they are recommended for use in production code generation. To view this table, in the MATLAB Command Window, type showblockdatatypetable, or consult the block reference pages.

Block Set Support for Code Generation

Several products that include blocks are available for you to consider for code generation. However, before using the blocks for one of these products, consult the documentation for that product to confirm which blocks support code generation.