MATLAB automatically generates C code

Source: Internet
Author: User

1. Prepare m file simpleproduct.m

function C = Simpleproduct (A, B)
C=a*b;

2. Enter coder in the MATLAB work interface and enter the project name Simpleproduct

3. Add the simpleproduct.m file to the project

4. Define the data type of the input variable A/b

5. Generate a MEX function to test whether the program is correct

6. Generate C code, tick generate code only

7. Under the codegen/lib/simpleproduct/of the current directory, you can see that a heap of. C and. h files are generated

$ ls codegen/lib/simpleproduct/
buildinfo.mat   rt_nonfinite.h               SIMPLEPRODUCT_REF.RSP
html             rtw_proj.tmw                 simpleproduct_rtw.mk
rtgetinf.c      rtwtypes.h                   simpleproduct_ TERMINATE.C
rtgetinf.h      simpleproduct.c              simpleproduct_terminate.h
rtgetnan.c      simpleproduct.h             SimpleProduct_types.h
rtgetnan.h      simpleproduct_initialize.c
rt_nonfinite.c  simpleProduct_ Initialize.h

8. Create a new C project, copy all the. C and. h files under codegen/lib/simpleproduct/to the project and create a new MAIN.C file with the following contents:

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "simpleProduct.h"
  4. #include "simpleproduct_initialize.h"
  5. #include "simpleproduct_terminate.h"
  6. int Main ()
  7. {
  8. Simpleproduct_initialize ();
  9. printf ("%lf", Simpleproduct (5,6));
  10. Simpleproduct_terminate ();
  11. return 0;
  12. }

9. Compile the project and view the results of the operation

MATLAB automatically generates C code

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.