Key Features

MATLAB Coder app (left) and code generation report (right) showing generated C code.

Run Anywhere

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.

Generate readable and portable C and C++ code from MATLAB code, including over 1,200 functions used for applications ranging from image processing and computer vision to advanced DSP and communications systems development.

Generated code for matrix multiply.


MATLAB Coder Successes

See how other engineers like you are finding success with MATLAB Coder:

  • VivaQuant generated fixed-point C code from heart rhythm monitoring algorithms and compiled it for an ARM® Cortex®-M processor.
  • Delphi generated C code for an automotive radar sensor alignment algorithm and compiled it for an ARM10 processor.
  • Respiri generated C code from acoustic respiratory monitoring algorithms and compiled it for an iPhone app, an Android™ app, and cloud-based server software.
  • DorsaVi developed motion analysis algorithms for medical, sports, and occupational safety applications using MATLAB Coder.

DorsaVi’s ViMove sensors in a running test.


Supported Toolboxes and Functions

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.

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.)

MATLAB language and toolbox support for code generation.


Prototype on Hardware

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®. 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.

Generate code and create an executable to prototype on a desktop PC.
Integrate code generated by MATLAB Coder into an iPhone or iPad app using Apple’s Xcode IDE.

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.

Prototyping algorithms quickly on hardware, from desktop to mobile to embedded systems.


Integrate with Software

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.

Integrate code generated by MATLAB Coder into a parent Microsoft Visual Studio project.
Integrate code generated by MATLAB Coder into an iPhone or iPad app using Apple’s Xcode IDE.

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.

Run unit tests written in MATLAB on your hand written C code and check if changes to your C code results in any unit test failures. Use visualization and other tools available in MATLAB to understand how your code is behaving.

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.

Interactive traceability report using MATLAB Coder with Embedded Coder.


Optimize Performance of the Generated 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.

Example of generated code with calls to OpenMP.


Reuse MATLAB Tests on Generated Code Prior to Integration

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.

Use the MATLAB unit testing framework to check if changes to your MATLAB code results in any unit test failures in the C code generated by MATLAB Coder.

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.

Verifying behavior of generated code before integrating with your application.


Accelerate Algorithms

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).

Generate a MEX-file to accelerate simulation of a DCT-based image compression or decompression algorithm.

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.

In this webinar you will learn how to use to various techniques to accelerate your communications system simulations in MATLAB and Simulink.