You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Convert Matlab script in C++ ?
1 view (last 30 days)
Show older comments
Hello,
I have a Matlab script that I would like to convert in C++, is it possible to do that with Matlab Coder ? Because, when I add my script as an Entry-Point File, I get this message: "All Entry_Point Files must be functions".
Can Matlab Compiler do the conversion from the script to C++ ?
Thank you in advance for your answer.
Fanta C.
27 Comments
Denis Gurchenkov
on 25 Aug 2015
MATLAB Coder does not support scripts (yet). Just make your script into a function.
Fanta Camara
on 26 Aug 2015
Thank you very much for your answer ! Do you know if functions for kinematics calculations from Matlab Robotics toolbox are also supported by Matlab coder ?
Denis Gurchenkov
on 27 Aug 2015
It looks like a number of functions under matlab/toolbox/robotics got MATLAB Coder support in R2015a release (were not supported in earlier releases). If you can name a particular function, I can check that one.
Fanta Camara
on 28 Aug 2015
Edited: Fanta Camara
on 28 Aug 2015
I am using Link and SerialLink classes and kinematics functions such as fkine and ikine.
I tried to generate C code with R2014b for the forward kinematics and I got the following error message: "Nested functions are not supported by Matlab Coder". I don't understand why I get this error because I don't use any nested function. My function is in attached file, if you can have a look on it please and tell me what is wrong. Thanks a lot.
Walter Roberson
on 28 Aug 2015
Move the lines before the "function" line to after the "function" line.
Fanta Camara
on 28 Aug 2015
Sorry, I don't understand what to do.
Walter Roberson
on 28 Aug 2015
Your file starts with some comment lines and might even have a "clear all" there. Delete those lines. The very first line in your forkin.m should be the line that starts with the word "function". This might possibly prevent the code from being thought to be a nested function.
Denis Gurchenkov
on 28 Aug 2015
MATLAB Coder ignores the comment lines, there is no need to move them down after "function" line, that's not the problem. I ran codegen on your forkin.m and I don't see the "All entry point files must be functions" problem. Did you use some other file, not that one?
Also, I can't fine any functions called Link and SerialLink in MATLAB. Can you please tell me where you got those? Are they part of some third-party library? If you type "which Link" in MATLAB -- it'll tell you where that function comes from.
Walter Roberson
on 28 Aug 2015
My speculation is that there were additional lines of executable code not shown in what was posted.
Fanta Camara
on 31 Aug 2015
Hello, sorry for the delay. Firstly, thank you very much for your replies. Yes, you are right Denis, before it was a script, that's why I couldn't converted it, but now I have a new file with my function. Link and SerialLink are robot manipulator's classes in Matlab Robotics System Toolbox, they are used for the calculation of robot kinematics, etc.
Now,when I try to convert my file, in attached document, with Matlab R2015a, the conversion fails, I still have errors from the Code generation Readiness tool concerning functions and cell arrays that are unsupported. But Link and SerialLink classes can used converted in C++, because they are recognized by the code generation readiness. Thank you.
Walter Roberson
on 31 Aug 2015
I do not see any cell arrays in that routine?
Fanta Camara
on 31 Aug 2015
These errors come from internal functions in the Robotics toolbox such as functions: fieldnames, setfield, getfield, rethrow, sym... the problem is that I don't directly use them.
Walter Roberson
on 31 Aug 2015
You appear to be using the Peter Corke robotics toolkit, tested against R2011b at latest, with no support. It was not designed for code generation. The Robotics Toolkit that Mathworks supports for code generation is their Robotics Systems Toolkit which supports deploying under their ROS (Robotic Operating System).
(I note by the way that Peter has placed his code in github at https://github.com/petercorke/robotics-toolbox-matlab -- but that version does use cell arrays as well)
It is common for generalized packages to support options processing by way of optional fields in structures. Unfortunately that interface is not compatible with code generation, as C and C++ structures must have fixed fields.
Fanta Camara
on 31 Aug 2015
You are right, I am using Peter Corke toolbox because I tought Peter Corke Robotics Toolbox was the same as Matlab Robotics Toolbox. Do you think that I can generate C code with Matlab toolbox without using Simulink ? And can I use the ROS under Windows ? Because at the end, I will integrate the generated C code to my Visual C++ project. Thank you very much Walter.
Walter Roberson
on 31 Aug 2015
http://www.mathworks.com/help/coder/ug/functions-supported-for-code-generation--categorical-list.html does not list any functions in the Robotic Systems Toolbox, the functions of which are listed http://www.mathworks.com/help/robotics/functionlist.html
It is supported by MATLAB Compiler, but that does not generate code. On the other hand, with MATLAB Compiler SDK you can use Compiled functions with .NET (this is not code generation; the MATLAB engine is called upon to do the work.)
Fanta Camara
on 1 Sep 2015
Thank you so much. You mean I can use Matlab Compiler with Peter Corke's robotics toolbox too ?
Denis Gurchenkov
on 1 Sep 2015
Yes, you should be able to use Matlab Compiler with Peter's toolbox.
Fanta Camara
on 1 Sep 2015
Oh, that would be cool. Thank you !
Walter Roberson
on 1 Sep 2015
Just keep in mind that the Compiler produces a .exe or .dll not code.
Fanta Camara
on 2 Sep 2015
Yes, I understand. I would like to use Matlab Compiler SDK with should create an header file that I can integrate to C++ code. But is it possible the executable returns some values ? Because in Matlab, my function returns a matrix, and I wonder if it will be the same with the executable.
Walter Roberson
on 2 Sep 2015
Yes, you can do that with Compiler SDK
Fanta Camara
on 2 Sep 2015
Ok, thank you very much !
Steven Lord
on 2 Sep 2015
Denis @ 1 Sep 2015 at 11:57,
If this third party robotics toolbox uses Symbolic Math Toolbox, as Fanta's comment @ 31 Aug 2015 at 9:29 suggests, it will NOT be able to be compiled with either MATLAB Compiler or MATLAB Coder.
Fanta Camara
on 3 Sep 2015
The problem is that I don't know if this toolbox uses Symbolic Math Toolbox.
Fanta Camara
on 3 Sep 2015
I don't have Symbolic Math Toolbox on my computer, so I guess the Robotics Toolbox works without using it.
Walter Roberson
on 5 Sep 2015
It appears that with the newly released R2015b, a number of functions in the Robotics Toolkit (the Mathworks one) support code generation. See http://www.mathworks.com/help/coder/ug/functions-supported-for-code-generation--categorical-list.html#buymxey
Fanta Camara
on 8 Sep 2015
Thanks for the information ! Actually, as you suggested I could create an executable from Matlab compiler SDK. I will try now to integrate it to my project. Thank you very much guys for your help!
Answers (0)
See Also
Categories
Find more on Code Generation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)