Matlab coder to generate C + + code steps from matlab

Source: Internet
Author: User

Matlab coder can generate independent, readable, portable, C + + code from MATLAB code.

3 steps to generating code using MATLAB coder:

Prepare the MATLAB algorithm for generating code;

Check the compatibility of MATLAB code (some MATLAB code statements do not generate C + + code);

Generate end-use source code or MEX.

Use MATLAB coder to generate C + + code and verify in vs2013:

A simple example of multiplying two numbers :

1, install matlab2014a or update version;

2, simple to generate a FOO.M file;

function C = foo (A, b)% #codegen

%this function muliplies A and b

c = A * b

of which,% #codegen可以防止出现警告错误

3, in the Command window, enter MEX-SETPU, select an existing compiler;

4. Enter coder (graphical interface) in the command window and press ENTER to eject the MATLAB Coder Project dialog box;

5. Enter a project name in the new tab name FOO.PRJ; Click OK to eject the MATLAB Coder MEX Function dialog box;

6, in the Overview tab, click Add Files, Pop-up dialog box, check FOO.M open;

7. Click Variable A, select Define by Example ..., pop up the Matlab coder Define by Example dialog box, enter 5 in MATLAB expression, click OK, and the same variable B to do the corresponding operation, enter 6;

8. Select the Build tab, the Output type is selected in A/C + + Static Library; check generate code only;

9. Click the more settings,generalàlanguage Select c++;interface option to remove all options; Close;

10, click on Build, compile, click View Report, pop Up the Code Generation dialog box, at this time, variables a, B, C will display the corresponding variable information;

11, the use of vs2008 to establish a console application program, the generated related files foo.h, foo.cpp, rtwtypes.h, foo_types.h copy to the relevant directory and add to the application;

12, add # include "StdAfx.h" in the Foo.cpp file;

13. The code in the Test.cpp file is:

#include "stdafx.h"

#include "foo.h"

#include <iostream>

using namespace Std;

int _tmain (int argc, _tchar* argv[])

{

Double A = 0.0, B = 0.0, c = 0.0;

cin>>a>>b;

c = Foo (A, b);

cout<< "C =" <<c<<endl;

return 0;

}

Reference: http://blog.csdn.net/fengbingchun/article/details/6793826

MATLAB and C + + mixed programming Reference: http://www.cnblogs.com/lidabo/archive/2012/08/24/2654148.html

Matlab coder to generate C + + code steps from matlab

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.