3

I want to realise a computer vision algorithm, coded in MATLAB on a hardware. I know that I can use serial communication to interact with MATLAB and Arduino through pc. But, I want to create a standalone hardware device. Is it possible to accomplish the task using a Raspberry Pi board. Will I be able to burn my code onto it, and use it solely to control other hardware (like a relay,etc.) that I need to?

Ryan Livingston
  • 1,898
  • 12
  • 18
Samdish Arora
  • 79
  • 1
  • 8
  • 1
    It will be cheaper, and might actually be easier, to try port your code to Python. `numpy` was designed to be very similar to MATLAB... – Dan Feb 09 '16 at 11:22
  • 1
    [Octave](https://www.gnu.org/software/octave/) might be an option – Steve Feb 09 '16 at 11:31
  • 1
    Matlab is not the best solution for such a system. It is good for fast programming but has several problems for your task. You could try to create a executable, but matlab cannot cross-compile. You need therefore run Matlab on a raspberry pi and create it there. Personally I would not do it. Could you swap your main code to a java/ C library? Then you could still use it in Matlab and a python/ Java program on the raspbery pi. – Mo3bius Feb 09 '16 at 11:36
  • @Mo3bius: The Matlab Coder and Embedded Coder offer exactly what you claim is impossible. – Daniel Feb 09 '16 at 11:40
  • @Daniel: Matlab cannot cross-compile. It can transfer most functions to C/C++ with the matlab coder tollbox though. This code is then not specific to Windows/Mac/Linux. That code can then be cross-compiled with gcc etc. For me that's a difference. As pointed out, this might be expensive. The only prices I found: http://www.embedded.com/electronics-products/electronic-product-reviews/programming-languages-and-tools/4215024/Generate-C-and-C--code-automatically-courtesy-of-MathWorks. (starts at 3K) – Mo3bius Feb 09 '16 at 11:50

2 Answers2

1

There are two solutions you can use.

The Raspberyy Pi Support Package from Simulink is designed to write standalone applications which run on the Raspberry Pi. This requires you to switch from Matlab to Simulink. Using a MatlabFunction Block in Simulink you should be able to reuse large parts of your code, only requiring you to redo the actual connection to the IO.

The second alternative is using the matlab coder to generate C++ from your matlab code.

Before reading any documentation page about these options, check the price tags for the required toolboxes. I think the Simulink coder is required for the Simulink support package, but I am unable to find that Information.

Daniel
  • 36,610
  • 3
  • 36
  • 69
0

As a researcher, I used Matlab a lot. And my preferred work pattern was

  1. Use Matlab to analyze a lot of different algorithms
  2. Find the best algorithm (fastest, most precise, ... you can define "best" in many different ways)
  3. Once the best algorithm is defined, port it to C++/C#/python (it depended on the final application)

The reason? Matlab code is slooooooooooooooooow and very poorly portable, but it already have lots of functions. So when you have to switch between algorithms it's a good choice, but once you decide the best algorithm you'd better switch to better languages.

For your case, if the application is already in the "searching for the best algorithm" phase you don't need to move it to a raspberry. If you already found it, port it to C/C++ and compile it on a raspberry, or port it to python and execute it

frarugi87
  • 2,826
  • 1
  • 20
  • 41