MATLAB Coder generates code from a subset of the MATLAB language typically used by design engineers for developing algorithms as components of larger systems. The supported subset includes more than 400 operators and functions from MATLAB.
A limited set of functions are supported for code generation from Aerospace Toolbox, Fixed-Point Designer™, Image Processing Toolbox™, Signal Processing Toolbox™ and Statistics Toolbox™. MATLAB Coder also supports code generation from many System objects™ found in the Communications System Toolbox™, Computer Vision System Toolbox™, DSP System Toolbox™, and Phased Array System Toolbox™.
MATLAB Coder supports a broad range of MATLAB language attributes to develop algorithms. These include:
Matrices and arrays, such as persistent variables, global variables, matrix operations, N-dimensional arrays, subscripting, and frames
Classes and data types, such as complex numbers, integer match, double/single precision, fixed-point arithmetic, characters, structures, numeric classes, and variable-sized data
Programming constructs, such as MATLAB program control statements (if, for, while, switch) and arithmetic, relational, and logical operators
Functions, such as function handles, sub-functions, the subset of MATLAB functions, variable length input and output argument lists, and the ability to call MATLAB functions
See the full list of supported MATLAB language attributes for code generation.
Translating MATLAB algorithms to C code involves specifying implementation requirements. MATLAB Coder guides you through this iterative process while enabling you to stay within the MATLAB language. You ensure that your algorithm is compliant for code generation by generating a MEX function that wraps the compiled code for execution back within MATLAB. MATLAB Coder produces a report that identifies any errors which must be fixed to make your MATLAB algorithm compliant for code generation. You iterate between fixing errors and regenerating a MEX function until your MATLAB algorithm is suitable for code generation.
You can now generate either C or C++ source code or a MEX function tuned for performance from your MATLAB algorithm.
C or C++ source code enables you to:
The MEX function can be called in place of the original MATLAB code to:
The MATLAB Function block for simulation and code generation lets you add MATLAB algorithms written in the MATLAB subset for integrating MATLAB code into Simulink models. Simulink Coder lets you generate code from these Simulink models that contain MATLAB code.
Embedded Coder generates code for supported embedded processors, on-target rapid prototyping boards, and microprocessors used in mass production. It extends MATLAB Coder and Simulink Coder by providing configuration options and advanced optimizations for fine-grain control of the generated code’s functions, files, and data. Embedded Coder improves code efficiency and facilitates integration with legacy code, data types, and calibration parameters used in production.
Code generated with Embedded Coder can be exported into third-party development environments, enabling you to automate the creation of an executable to deploy on your embedded system. The generated code can also be executed on processors to verify behavioral performance and gather resource utilization metrics through processor-in-the-loop (PIL) and profiling techniques.