5

I need to convert some MATLAB code to C++. I am using Visual Studio 2010 and have MATLAB compiler installed. I am wondering how do I go about doing this.

Also when I publish my project will the end user have to install anything by MATLAB? (this cannot be the case)

Amro
  • 123,847
  • 25
  • 243
  • 454
ddd
  • 269
  • 1
  • 6
  • 15

3 Answers3

3

You can compile Matlab scripts into standalone executables, but I'm not familiar with a Matlab tool to convert Matlab code to Visual C++ code. You can convert Matlab code to C or C++ using Simulink Coder (formerly Real-Time Workshop), which is available from Mathworks as a separate product.

To run the standalone executable, the user will have to install the Matlab Compiler Runtime. From the Matlab Compiler web page:

Executables and libraries created with the MATLAB Compiler product use a runtime engine called the MATLAB Compiler Runtime (MCR). The MCR is provided with MATLAB Compiler for distribution with your application and can be deployed royalty-free.

eykanal
  • 26,437
  • 19
  • 82
  • 113
  • A long, long time ago, the MATLAB compiler used to translate MATLAB code to C, but it has not done that for some time. Nowadays, it just converts the (*.m) MATLAB source files to an obfuscated, pre-parsed format (.p), packaged up so that it can be either run as a standalone executable or called from another program. Either way, the target machine on which it is to be run will need to have installed the MCR from the version of MATLAB against which the application was developed. – William Payne Oct 11 '11 at 21:20
  • 1
    "but I don't think there's a Matlab tool to convert Matlab code to C++ or Visual C++ code"-Misinformation: There is such a Matlab tool and it is called real time workshop. However, this is a separate product to the Matlab compiler and requires a different license. – learnvst Jan 26 '12 at 12:39
2

You will not get rid of the Matlab runtimes. I often had problems using Matlab Compiler. It basically is like a wrapper around the Matlab runtime, generates clumsy code and did introduce many problems for deployment. C alternatives ... ? I could not find any. So I recently switched to ilnumerics, which is like Matlab in C# - only much faster and no translation necessary. it works out great so far because we use ASP.NET anyway and hence save jumping between languages and can directly use the 3d plots of ilnumerics.

Paul Wendler
  • 325
  • 3
  • 9
0

Another option you have is to use the MATLAB Engine. It probably isn't an option for real-time applications, but otherwise it's really nice. You basically call MATLAB functions right from C++. Figures (plots) will be display just as if you were running local MATLAB. When the program starts, a MATLAB console is created.

Derek Greer
  • 131
  • 5