1. Create an M file (test. m) in MATLAB)
For example:
Function Test (H, d)
For x =,
If X & gt; d
Y = h;
Hold on;
Plot (x, y)
Elseif X & lt;-d
Y =-h;
Hold on;
Plot (x, y)
Else
Y = H/(d * X );
Hold on;
Plot (x, y)
End
End
Enter the deploytool command in MATLAB r2007a (enter comtool in MATLAB) to open the MATLAB build. create a project in the. NET window. In this project, add files to test. M file, build to generate the COM component, which is test. DLL is the COM component that we will reference in C.
MATLAB automatically registers the DLL in the Registry during build.
However, we still need to make preparations before, open the Start Menu "run", enter regsvr32 "Matlab installation path \ bin \ Win32 \ mwcomutil. DLL ", that is, for mwcomutil. DLL registration (This dll is used by any COM component of MATLAB). We can use it when downgrading other compilers.
2. You can call the DLL file in C # as follows:
"Reference" right-click, select Browse, find test. dll, and Add.
"Reference" right-click, select Browse, find mwarray. dll (MATLAB installation path \ toolbox \ dotnetbuilder \ bin \ Win32 \ V2.0 \ mwarray. dll), and Add.
Write the following code:
Test. testclass ST = new test. testclass ();
Mathworks. MATLAB. net. arrays. mwarray M = 1, n = 2;
St. Test (m, n );