In the "Analysis of VC and MATLAB joint programming < a >" and "Analysis of VC and MATLAB joint programming < two >" introduced matcom, this tool can be written in Matlab, the M file translated into C + + files, or executable (EXE) or library files (DLL). But matcom in many aspects also have limitations, for example, to struct and other classes of support is flawed, some of the drawing statements can not achieve or get accurate images, especially the three-dimensional image.
In fact, VC and MATLAB interface to achieve a variety of methods, matcom is just one of them, this article introduces a relatively easy to implement the method: COM interface method. COM (Compponent object Model module) is a more complex technology, the details of a few books can not finish, so here is not to introduce, this article through an example of how to do in the MATLAB COM components, and how to call the COM components in VC.
First in the MATLAB editor to edit the M function file: Start Matlab->file->new->m-file function content as shown in Figure 1: This function has no input and output parameters, the file is saved as HUATU.M.
Figure 1 m function huatu.m
In the MATLAB set up the COM component, the steps are as follows:
1, in the MATLAB command window to enter the following commands:
>> Comtool
The COM editing interface appears, as shown in Figure 2:
Figure 2 COM Component Editing interface
2, New project: File->new project ..., as shown in Figure 3.
Figure 2 COM Component property settings