| Finally implement C # Call the Matlab function (zz) . NET is the development direction of Microsoft. In the future, we will inevitably call some MATLAB languages when developing software. We have been calling MATLAB with C # In the *** figure tonight and finally succeeded. The main idea is to first make the m function of Matlab into a COM component, and then apply the COM component in C. The main steps are as follows: 1. Create an M file (test. m) For example: Function Test (H, d) For x =, If X> d Y = h; Hold on; Plot (x, y) Elseif x <-d Y =-h; Hold on; Plot (x, y) Else Y = H/(d * X ); Hold on; Plot (x, y) End End 2. input the comtool command in MATLAB to open the MATLAB com builder, Click file-new project to create a new project, Enter the name in component name and click OK. Then click Project -- add files to add test. m to the project, Click build-COM object, and a test1_0.dll will be generated in the comtest \ distrib \ folder ( COM component ), MATLAB automatically registers the DLL in the Registry during build. We also need to make preparations to go To the <MATLAB root>/bin/Win32 Directory (on your machine MATLAB installation path), enter regsvr32 mwcomutil. dll, that is, to register mwcomutil. dll (this DLL Is the DLL used by any COM component in MATLAB). We can use it when downgrading other compilers. . 3. C # Implementation call Create a C # project (I use vs. net2003) and select reference in Solution Explorer on the right. , Right-click, select Add reference, select COM in the pop-up window, and find test_1_0. dll. Click Select, and then click OK. At this time, the COM component is added to the project. We can also choose Then writeProgram Test. testclassclass ST = new test. testclassclass (); Object M = 1, n = 2; St. Test (m, n ); You can. Then the figure we want to get appears in C #. |