Matlab to C++ Converter??

Hi, may I know is there any build in converter inside Matlab R2010b? TQ...

Answers (3)

Walter Roberson
Walter Roberson on 24 Feb 2012

0 votes

You can get the optional (costly) MATLAB Coder product.
There are a fair number of restrictions as to what can be converted. For example, no graphics.
Superb
Superb on 24 Feb 2012

0 votes

can that Matlab coder works on R2010b? TQ...

10 Comments

Good question. MATLAB Coder was released for R2011a .
There were other products before that, but I am not certain that this kind of generation was available for MATLAB itself (as opposed to Simulink.)
Note: the list price for MATLAB Coder is $US6,500; if you are going to spend that much it would seem to make sense to pay any differential support costs needed to bring your MATLAB to a current version.
But please don't spend that kind of money without having studied the details of what MATLAB Coder can and cannot compile. It is primarily for numeric algorithms at the moment, with little support for data structures or toolboxes.
Superb
Superb on 24 Feb 2012
Thanks...Can I get a student version? I'm currently still a Uni student who need to do a Final Year Project...
Does your university have a license?
MATLAB Coder and all related products are *not* available for the Student Version.
They _are_ available in the Academic version, but there are license restrictions about who can compile and distribute what and to whom. I have outlined my _interpretation_ in some past messages, but it would be far better to talk to your university's account representative.
Superb
Superb on 25 Feb 2012
I think there is...I tried to get from my Uni and install 1st...is that just install Matlab R2011a enough? I mean is it the Matlab Coder is already inside R2011a itself? Or I need something else to install? TQ...
I do not know if it is on the standard distribution media or not these days. If it is, it would have to be specifically selected for installation.
Superb
Superb on 25 Feb 2012
Yes, I've try to get from my Uni, that's included...I can use it now...just don't know why it cannot run...this is the error i got...
coder -build 1.prj Could not locate the MEX compiler options file mexopts.bat. Run mex -setup to select the MEX compiler and create the MEX options file. Use help codegen for more information on using this command.
You need to have a (supported) C or C++ compiler installed, and you need to run
mex -setup
to tell MATLAB which compiler to use.
Superb
Superb on 26 Feb 2012
Thanks Walter...Can I use Visual Studio 2010 C++? How to connect VSC++ with MATLAB in this case?
TQ...
You upgraded to R2011a ? If so then Yes, VS 2010 C++ can be used.
If you are using MATLAB in 64 bit mode then there is additional work involved; see http://www.mathworks.com/support/compilers/R2011a/win64.html

Sign in to comment.

Superb
Superb on 26 Feb 2012

0 votes

Yes, I'm using R2011a from my Uni now...and I use a 32 bit Windows 7...I think it should work fine right? But how to connect them together? TQ...

7 Comments

So did you run
mex -setup
and selected Visual Studio 2010? Then try running your coder project again.
Superb
Superb on 26 Feb 2012
Thanks Jiro...I have done what u said...and yes, mex -setup is install now...A question here is, is that mex -setup can be use to generate C++ code too? Or it's just generate mex code?
Another question is, when I tried to Build the project, it give me error...
>> coder -build 1.prj ??? Try and catch are not supported for code generation. Error in ==> PNRS Line: 327 Column: 1 Code generation failed: Open error report.
Can I know why "try" is not supported? TQ...
With MATLAB Coder, you can generate both C/C++ code as well as MEX. In general, MEX is just a wrapper around the C code and compiled to run in MATLAB. In the coder project, you can specify the output type to be MEX, C/C++ library, or C/C++ executable. In all cases, you can see the C source code.
I can't really tell you _why_ "try" is not supported. It just is not.
http://www.mathworks.com/help/toolbox/eml/ug/bq37dee.html
Superb
Superb on 27 Feb 2012
Thanks Jiro for the respond...so may I know how to by pass "try", so that I can continue to convert it? TQ...
There is no C equivalent to "try" (at least not that is of any practical use to anyone if you are not writing your own processor kernel code.)
C++ has exceptions, but the mechanisms do not correspond at well to MATLAB's exceptions.
Superb
Superb on 28 Feb 2012
I'm trying to convert into C++, but where can I choose to only convert to C++? It's because it only shows "C/C++" but not "C++", can I do that? TQ...
And u say, "if you are not writing your own processor kernel code.)", is that means if I convert directly using coder but not writing the whole code on my own? TQ again for explanation...
I have gathered the impression that the code generated is in the common subset of C and C++, except that C++ style declarations might be used for external functions, extern "C" { .... } . There might be some other differences, perhaps; no one has happened to mention them in the messages I've read (the price of the toolkit is sufficiently high that there is no chance my workplace will buy it in the near future.)
If you did manage to find a way to generate C++ code, it still would not handle try/catch . C++'s exceptions are not the same thing.
My mention about writing processor kernel code has to do with the fact that the exception processing that _is_ possible in C, is of such limited flexibility, that nearly the only use for it (other than saying "I quit") is in embedded processing systems with paged memory, to detect a segmentation violation, swap in the appropriate page, and continue on. Not at all the kind of thing you are looking for.
It seems plausible to me that if you are using library routines that might produce meaningful exceptions for try/catch use, then _probably_ your code is not in the subset that can be compiled.
Verify your inputs before you send them to the lower levels so that you do not need to rely on try/catch.

Sign in to comment.

Tags

Asked:

on 24 Feb 2012

Edited:

on 25 Oct 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!