MATLAB Coder™ translates your MATLAB code into ANSI/ISO C and C++ code that is efficient, readable, and portable. You can use any C compiler to compile and run the generated code on any hardware, from desktop systems to mobile devices to embedded hardware. The generated code is royalty-free—deploy it in commercial applications to your customers at no charge.
With automatic code generation, you can spend less time writing, debugging, and maintaining low-level C code. Spend more time developing your ideas in MATLAB. As your design evolves, let MATLAB Coder automatically propagate changes to the generated code, avoiding costly manual translation errors, which means you can iterate faster and get to market sooner. MATLAB Coder enables you to use your golden reference MATLAB code both for prototyping and for production, simplifying workflows and communication within your organization.
See how other engineers like you are finding success with MATLAB Coder:
MATLAB Coder generates code from a broad range of MATLAB language features that design engineers typically use for developing algorithms as components of larger systems. This includes more than 1700 operators and functions from MATLAB and companion toolboxes.
Use MATLAB Coder with Deep Learning Toolbox™ to deploy trained deep learning networks to CPUs. You can deploy to Intel® processors that support the Advanced Vector Extension 2 (AVX2) instruction set, as well as the Intel Xeon family of processors. You can also deploy to the ARM® processors that support the Neon instruction set architecture (ISA), like the ARM Cortex®-A family. MATLAB Coder generates code for preprocessing and postprocessing along with the trained deep learning network, so you get the complete algorithm. For example, you might need to clean up foggy input images using classical machine learning techniques before using a trained deep learning network like AlexNet to detect and classify objects. MATLAB Coder generates code for both the machine learning algorithm and for the trained deep learning network, so you can develop your complete application more easily.
If your algorithm uses additional functions and features, consider also using MATLAB Compiler SDK™ to deploy the complete application, including the graphical user interfaces. (See a detailed comparison of how MATLAB Coder and MATLAB Compiler approach deployment.)
Using the MATLAB Coder app (or equivalent command-line functions), you can quickly generate code and compile it for your hardware no matter what your application does, ranging from signal processing, computer vision, image processing, or control systems.
Generate code and prototype it on embedded platforms such as Raspberry Pi or Arduino®. You can use MATLAB® Support Package for Raspberry Pi™ with MATLAB Coder to generate and deploy your algorithms as standalone applications on a Raspberry Pi.
On mobile platforms, integrate the generated code into your own app and run it on iPhones, iPads, or Android devices, including accessing onboard sensors such as the video camera, microphone, and accelerometer. If your end target is an Intel®-based desktop or laptop, compile the generated code into a standalone static or dynamic library, or an executable that can run outside the MATLAB environment.
Use MATLAB Coder with Deep Learning Toolbox to prototype and deploy trained deep learning networks to Intel processors that support the Advanced Vector Extension 2 (AVX2) instruction set, like the Intel Xeon family of processors, and ARM processors that support the Neon instruction set architecture (ISA), like the ARM Cortex A family.
By using MATLAB Coder with Embedded Coder®, you can go beyond prototyping to production. Generate code that takes advantage of processor-specific intrinsics. These can execute faster than standard ANSI/ISO C/C++ code. Available libraries include those for ARM® Cortex®-A and Cortex®-M platforms. You can profile execution time of the generated standalone code. Verify the numerical behavior of the generated code using software-in-the-loop (SIL) and processor-in-the-loop (PIL) execution. Finally, gain insight into the generated code with interactive traceability reports that show you where the generated C code came from and where your MATLAB code went. A static code metrics report helps you understand memory usage.
By using MATLAB Coder with GPU Coder™, you can prototype on GPUs such as the NVIDIA® Tesla® and embedded Jetson™ platforms by generating CUDA® code for deep learning, embedded vision, and autonomous systems.
MATLAB Coder generates C code with simple interfaces, and this code is easy to integrate. You can integrate the generated code as source code, static libraries, or dynamic libraries into your application running outside of MATLAB on the desktop, cloud, mobile, or embedded systems. Use platform-specific libraries (such as LAPACK for linear algebra and FFTW for Fast Fourier Transforms) for maximum performance. Or you can generate pure source code for the best readability and portability.
Generated code uses C types in a natural way, providing an easy interface to integrate with external code. For structures, fixed-size arrays, scalars, and all numeric data types, generated code uses the corresponding C types directly. Advanced data types such as variable-sized arrays and objects produce richer C types and utility functions to simplify working with them. An example main function is generated that shows how to invoke the generated code. You can choose to generate arrays in row-major or column-major order depending on the needs of your software environment. To integrate with external image processing libraries (such as OpenCV) without copies or transposes, you can select the row-major array layout.
If you have existing trusted C libraries or components, you can bring them into MATLAB for higher-fidelity testing in the MATLAB environment using MEX-function generation. You can then use
coder.ceval to call those components from your generated code as well.
By using MATLAB Coder with Embedded Coder, you can control the look and feel of the generated code. Match your company’s coding standards with custom
#define directives and file and function banners. If you need MISRA-compliant code, a single panel lets you customize code generation to maximize compliance. Use the interactive traceability report to gain insights into how your MATLAB code maps to the generated C code.
MATLAB Coder automatically applies optimizations to your code to give you the best results out of the box, but also gives you the control to adjust tradeoffs between execution speed, memory usage, readability, and portability. Profiling tools are available to help you understand the performance of the code and identify bottlenecks.
For additional acceleration, you can leverage third-party libraries. For example, you can optionally generate code that calls optimized libraries such as LAPACK and FFTW if these libraries are available in your target environment. You can hand-write C code for the most critical parts of your algorithm, while letting MATLAB Coder generate the rest.
Generate shared-memory multicore code from
parfor-loops and compile it with a compiler that supports the OpenMP application interface. For distributed parallelism, you can use Parallel Computing Toolbox™.
By using MATLAB Coder with Embedded Coder, you can further optimize the generated code by calling processor-specific intrinsic functions that execute faster on specific processors. Available libraries include those for the ARM® Cortex-A and Cortex-M platforms.
Use your existing MATLAB tests to verify the behavior of the generated code before integrating with your application. Evaluating results is easy in the interactive MATLAB environment. Using the MATLAB unit test framework (included with MATLAB), you can quickly develop a rich set of regression tests. MATLAB Coder understands MATLAB unit tests and can use them to verify the generated C code with instrumentation. The instrumentation enables clear and repeatable diagnostics for run-time errors, and prevents incorrect code from bringing down MATLAB.
By using MATLAB Coder with Embedded Coder, you can verify the numerical behavior of the final generated code on the host and target platforms using SIL and PIL execution.
As part of an overall strategy to accelerate your MATLAB algorithms, you can generate C code with MATLAB Coder and package it so you can call it as you would a regular MATLAB function (as a MEX-function).
The acceleration you experience will vary depending on the nature of your MATLAB code. The optimized numerical routines and heavily vectorized code in MATLAB typically cannot be made faster by code generation. Code with loops, structures, and fixed-point types will usually see larger benefits. Code with
parfor loops will take advantage of multiple cores if your C compiler supports the OpenMP standard. You can profile execution times of the generated MEX function to identify bottlenecks and focus your optimization efforts.
For some applications, you can combine multiple techniques for acceleration such as using vectorization and pre-allocation, System objects™, and Parallel Computing Toolbox with MEX-function generation.
By using MATLAB Coder with GPU Coder, you can improve execution speed by running parallelizable parts of your algorithm on the GPU.
Finally, if you are deploying a standalone application using MATLAB Compiler or MATLAB Compiler SDK, you can accelerate performance of the deployed application by replacing critical components with MEX-functions generated by MATLAB Coder.