MATLAB® can be used with C and C++ in a variety of ways. The two environments can be used together for signal processing design, including for calling MATLAB from C or C++, using MATLAB code directly in C, or using C code directly in MATLAB.
Calling MATLAB from C or C++
Creating algorithms directly in a C and C++ programming environment is second nature for most software engineers. However, the native capabilities that exist in C for crafting complex signal processing algorithms is limited. For this reason, many programmers invoke the MATLAB engine interface directly from their C program. This gives software engineers immediate access to built-in MATLAB functions such as FFTs and digital filters. It also allows full access to MATLAB visualization to plot and graph data, as opposed to looking at memory registers or text outputs from the C environment.
Using MATLAB Code Directly in C or C++
It is often necessary to integrate code developed in MATLAB directly into a C or C++ project. There are a number of ways in which to export your algorithm or design from MATLAB into a C development environment.
Create ANSI C Code Using MATLAB Coder
MATLAB Coder™ is an add-on product that allows you to generate portable and readable C or C++ code from your MATLAB code. This code can then be integrated directly into Microsoft Visual Studio or any other C/C++ development environment.
Create Shareable Libraries or Executables Using MATLAB Compiler
As with MATLAB Coder, MATLAB Compiler™ and MATLAB Compiler SDK™ are add-on products that enable software engineers to distribute their MATLAB based IP. While MATLAB Coder allows full access to the readable ANSI C code, MATLAB Compiler allows for the creation of standalone executables (.exe), and MATLAB Compiler SDK allows for the distribution of shared libraries (.dll).
Using C and C++ Code Directly in MATLAB
You can bring C or C++ IP into the MATLAB environment in two ways:
Compile C Code into MEX
Using the mex (MATLAB executable) command in MATLAB, you can compile C code into a native MATLAB function that can be invoked in a similar fashion to prebuilt functions.
Load a Precompiled Library
Using the loadlibrary command, a precompiled library (.dll) or shared object (.so) can be loaded into MATLAB so that the functions and algorithms within the library can be used by other MATLAB scripts, functions, or system objects.