Matlab to C++ Converter??
Show older comments
Hi, may I know is there any build in converter inside Matlab R2010b? TQ...
Answers (3)
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
on 24 Feb 2012
0 votes
10 Comments
Walter Roberson
on 24 Feb 2012
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
on 24 Feb 2012
Sean de Wolski
on 24 Feb 2012
Does your university have a license?
Walter Roberson
on 24 Feb 2012
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
on 25 Feb 2012
Walter Roberson
on 25 Feb 2012
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
on 25 Feb 2012
Walter Roberson
on 25 Feb 2012
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
on 26 Feb 2012
Walter Roberson
on 26 Feb 2012
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
Superb
on 26 Feb 2012
0 votes
7 Comments
Jiro Doke
on 26 Feb 2012
So did you run
mex -setup
and selected Visual Studio 2010? Then try running your coder project again.
Superb
on 26 Feb 2012
Jiro Doke
on 26 Feb 2012
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
on 27 Feb 2012
Walter Roberson
on 27 Feb 2012
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
on 28 Feb 2012
Walter Roberson
on 28 Feb 2012
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.
Categories
Find more on Call C++ from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!