Signals, states, and block parameters that you create in a model appear in the generated code as variables. Control the way that the code declares and defines these variables.
Generate efficient code by reducing memory usage and specifying numeric data types. Control the naming, definition, and usage of data types.
Ease the integration of the generated code with your own code by specifying identifiers and file placement of declarations and definitions.
Manage access to signal data and specify parameter tunability.
Package signal and parameter data into structures.
Improve code readability and traceability.
To calculate output data from input data, the generated code must store some internal data in memory, such as block state data and nonscalar parameter data.
The generated code stores data, such as signals and states, in global structures. Use the structures to access and integrate with the data.
The real-time model data structure describes the generated model code and enables your code to interact with the generated code.
Use a data store to explicitly model a piece of shared global data in the generated code.
Optimize the generated code and generate code for specific processors by controlling the data types that store parameter data in computer memory.
For signals, if possible, generate variables that are local to functions rather than in global storage.
Define data shared between Simulink, Stateflow, and MATLAB.
This example shows how to generate and optimize the code for a fixed-point air-fuel ratio control system designed with Simulink® and Stateflow®.
Work with code that the code generator produces for matrices and arrays.
Enable existing S-functions for row-major code generation by specifying the array layout.
coder.rowMajor inside the MATLAB Function block to generate
Convert existing column-major model to row-major for code generation.
Generate code by using the row-major and column-major algorithms for row-major array layout.
Simulate and generate code by using the interpolation algorithm for row-major and column-major array layout.
Simulate and generate code by using the interpolation with subtable selection algorithm for row-major and column-major array layout.
Simulate and generate code by using the Direct Lookup Table algorithm for row-major and column-major array layout.
Preserve dimensions of multidimensional arrays in generated code.
Preserve array dimensions for model data elements.
In the generated code, create tunable parameter data that you can access during rapid prototyping and calibration.
Reuse parameter data by creating a
Simulink.Parameter object or
numeric MATLAB® variable that you can use in different data type contexts.
Limitations can prevent a block parameter from appearing in the generated code as tunable, which means you cannot interact with the parameter value after compiling the code.
As you iteratively develop a model, capture output signal and state data that model execution generates. Tune parameter values during execution to observe results on the outputs.
Switch between independent sets of values for the same block parameters by storing the sets in an array of structures.
As you iteratively develop a model, you can tune block parameter values during simulation or execution of generated code to observe the results on signal and state values.
Customize the implementation of parameter arguments in generated code.
Generate code that enables you to store tunable initial conditions in memory, for example, for modeling a system that shuts down and restarts.
To match the numerics of a simulation in Simulink®, the generated code assigns initial values to global data, especially for block states and parameters.
Control the names of primitive, structure, and enumerated data types in the generated code.
Create structures of signal, state, and parameter data in the generated code.
Enumerated data is data that is restricted to a finite set of values. Create enumerations in the generated code.
Integrate the generated code with your own code by placing
typedef statements in generated and imported
Integrate the generated code with your code by specifying
the identifiers that correspond to Boolean
Also, specify the identifiers that correspond to data type limits,
which the generated code uses to determine overflows.