MATLAB can generate C code for ARM Cortex-M controllersAccording to

this article, Matlab Coder, one of the many tools Matlab has, can generate, from Matlab source code, readable ANSI C code that, with minimum modifications, could be easily ported for ARM Cortex-M controllers and compiled with Keil for ARM, LPCXpresso or other IDE. In theory the procedure can work also for AVR Atmega or any other controller with sufficient memory space.

The advantage seems to be quite significant because Matlab code is compact and complicated routines that do operations with matrices or perform signal processing, over a vector of data, are hard to implement directly in C. Only a simple matrix multiplication see (a) and (b), which is done by Matlab with a single line of code, require two "for loops" in C, and a few lines of text.

a) MATLAB code (just one line):c = a*b; %Multiplication of two matrices

b) Automatically generated C code from (a):void simpleProduct(const real32_T a[5], const real32_T b[10], real32_T c[2])

{

int32_T i0;

int32_T i1;

for (i0 = 0; i0 < 2; i0++) {

c[i0] = 0.0F;

for (i1 = 0; i1 < 5; i1++) {

c[i0] += a[i1] * b[i1 + 5 * i0];

}

}

}

Question: Has somebody tried, using Matlab coder, to convert to C, Matlab or Simulink programs and then port them to a microcontroller?

See : http://blogs.mathworks.com/loren/2011/11/14/generating-c-code-from-your-matlab-algorithms/ for more details