I am working on a complicated robotics project which involves MATLAB image processing algorithm and LEGO MINDSTORMS interface as well as an Arduino. The system works dependently in a sequence according to each reading either from the Arduino or to give a command to the LEGO bricks.

The question here is can I replace the processing from PC to another external microcontroller like Raspberry Pi for example but without converting the matlab code as installing MATLAB itself on the microcontroller to compile the code? If so, what microcontroller would be convenient for this and if no what is the best solution to control the system without the need of a PC.


3 Answers 3


Yes, there are a few processors powerful enough to run (some) programs written in the MATLAB language directly, replacing a PC.

So far, I only know 4 ways to do that:

If you have a motherboard powerful enough to run Linux, such as as BeagleBone or the Raspberry Pi or the Cubieboard, you could:

  • Install the open-source Octave tool, which can understand and execute many MATLAB-language programs directly. "Running Matlab Computer Vision on Raspberry Pi with Linux Octave. Part 1."(a)
  • Install the open-source Scilab tool, which can understand and execute some MATLAB-language programs directly.
  • Install the open-source FreeMat tool, which can understand and execute some MATLAB programs directly.

Often these approaches either don't bother producing any graphics at all on the embedded system, or use the open-source matplotlib library that is designed to be easy to use from within MATLAB as well as possible to run on any machine that can run Python -- even machines that can't run MATLAB.

While the Raspberry Pi can run (some) programs written in the MATLAB language using the above approaches, alas, the Raspberry Pi isn't quite PC-compatible enough to run MATLAB. "MATLAB for Linux on the Pi? No."(b)

If you have some "PC-compatible" (x86 processor) mini-PC, such as many PC104 and (all?) PCI-104 embedded systems, or the NUC, or the huge number of microATX and smaller motherboards, you could use any of the above options, or you could also:

  • Install MATLAB for Windows or MATLAB for Linux. "MATLAB for Linux system requirements"(c) (d) "Install Matlab in Linux" (e)

alternatives that don't quite meet that criteria

You probably already know that "running MATLAB code directly on a stand-alone microcontroller" is not that popular; other approaches include

  • Using MATLAB to develop Simulink models that run as stand-alone applications. "Raspberry Pi Support from Simulink" (f); "Run Simulink models on ... Arduino ... BeagleBoard ... Gumstix ... Raspberry Pi ... LEGO Mindstorms ..." (g) "Raspberry Pi Programming using Simulink"(h) (i) "MATLAB / Simulink on BeagleBone Black"(j) "Rapid BeagleBoard Prototyping with Matlab and Simulink"(k)
  • running MATLAB code on a PC that communicates back and forth with a microcontroller, to do things that neither one could do alone. "the MATLAB Support Package for Raspberry Pi Hardware"(l); "ThingSpeak Support from MATLAB ... with Arduino"(m)
  • Use MATLAB to try out a bunch of high-level algorithms and use that implementation to estimate how much RAM and processing power it needs, then later re-implement those algorithms from scratch to run stand-alone on practically any microcontroller with at least that much RAM and processing power. (Typically in Forth or C or C++, since practically every microcontroller has a compiler for those languages and hardly any other languages).

You can export C code from MATLAB using MATLAB CODER and compile that with a suitable compiler (or cross compiler). Any suitable platform probably has a C compiler available.

Whether the resources (such as RAM) are available on a microcontroller to run the code at all, and if at all, sufficiently fast, are other questions.

It's also possible to export hardware description language code from MATLAB if you need high speed, which can be used to program an FPGA.

The add-ons are not inexpensive if you're in a commercial environment (I think the academic terms are considerably more generous).

  • \$\begingroup\$ The problem here that I'm in a doubt that some functions MATLAB CODER cannot convert it into C and not supported by it so, can a microcontroller act as a PC in operating MATLAB and compiling the code or either installing an OS that support MATLAB?and if there any possibility how it could be done and through which microntroller?(this was specifically the question) \$\endgroup\$ Commented Aug 22, 2014 at 13:53
  • 1
    \$\begingroup\$ No you cannot run MATLAB itself on a microcontroller unless the microcontroller is essentially a PC running an operating system supported by MATLAB. \$\endgroup\$ Commented Aug 22, 2014 at 13:54
  • \$\begingroup\$ Apart from 'plain' Matlab Coder, there is also the Embedded coder extension which is meant specifficaly for embedded MCUs/MPUs including AVRs. \$\endgroup\$
    – venny
    Commented Aug 22, 2014 at 14:07
  • \$\begingroup\$ @venny He wants to run native code, not use MATLAB as a cross-development system. \$\endgroup\$ Commented Aug 22, 2014 at 14:38
  • \$\begingroup\$ @Spehro Pefhany Of course that is not possible, as you stated above. \$\endgroup\$
    – venny
    Commented Aug 22, 2014 at 15:27

Once I converted rather large Matlab project to C by an automatic tool ( Tmc compiler ) and run it on Android with Arm processor. The problem of Matlab language is that all variables should be allocated dynamically and the type size is undefined. Thus the effectiveness of the translation depands on malloc/free implementation. Indeed the dynamic memory allocation is dangerous and not acceptable for safety applications.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.