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.