How does Delphi use the. m file of Matlab ?,

Source: Internet
Author: User

How does Delphi use the. m file of Matlab ?,
Steps:
1. Compile the. m file into a. c file in matlab;
2. Use bcc32 to compile the. c file and obtain the obj file;
3. Call the obj file in Delphi;


Step 1. Compile the. m file into the. c file in matlab

A). Compile the test. m file.

Function [c, d] = test (a, B)
C = a + B;
D = a * B;

B) run the "maid" command, enter the coder in the work interface, and enter the Project name "test" in the "Create Project" dialog box of the Matlab Coder Project.

In the project on the right of the form, add the test. m file to the project,


After adding the test. m file, select the parameter type of the function input:



Switch to the Build page and set



Click compile.

The. c file is generated in your project directory.

Step 1 is complete.


Step 2. Use bcc32 to compile the. c file and obtain the obj file.

Create a bat file in the. c directory with the following content: (path: the actual path on your machine)

X :\... \ DXE8 \ bin \ bcc32-c-nBCCOBJ-IX :\... \ DXE8 \ Include; X :\... \ DXE8 \ Include \ Windows \ crtl rt_nonfinite.c
X :\... \ DXE8 \ bin \ bcc32-c-nBCCOBJ-IX :\... \ DXE8 \ Include; X :\... \ DXE8 \ Include \ Windows \ crtl rtGetInf. c
X :\... \ DXE8 \ bin \ bcc32-c-nBCCOBJ-IX :\... \ DXE8 \ Include; X :\... \ DXE8 \ Include \ Windows \ crtl rtGetNaN. c
X :\... \ DXE8 \ bin \ bcc32-c-nBCCOBJ-IX :\... \ DXE8 \ Include; X :\... \ DXE8 \ Include \ Windows \ crtl test. c
X :\... \ DXE8 \ bin \ bcc32-c-nBCCOBJ-IX :\... \ DXE8 \ Include; X :\... \ DXE8 \ Include \ Windows \ crtl test_initialize.c
X :\... \ DXE8 \ bin \ bcc32-c-nBCCOBJ-IX :\... \ DXE8 \ Include; X :\... \ DXE8 \ Include \ Windows \ crtl test_terminate.c


Pause


Save

Create a BCCOBJ directory in the same directory

Run the bat file


Under the BCCOBJ directory, six obj files are generated.

Step 2.


Step 3. in Delphi, call the obj file

You can reference these obj files in Delphi.


{$LINK bccobj\test_initialize.obj}{$LINK bccobj\test_terminate.obj}{$LINK bccobj\test.obj}{$LINK bccobj\rt_nonfinite.obj}{$LINK bccobj\rtGetInf.obj}{$LINK bccobj\rtGetNaN.obj}


Define the function to be used:
procedure _test_initialize(); cdecl; external;procedure _test_terminate(); cdecl; external;procedure _test(const a, b: Integer; var c, d: Integer); cdecl; external;

Call

var  a, b: Integer;begin  _test_initialize();  _test(2, 3, a, b);  _test_terminate();  Caption := Format('%d   %d', [a, b]);end;

Step 3.



Related Article

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.