MATCOM is a tool launched by mathtools to convert m Files into C ++ code with the same functions. Compared with the compiler provided by MATLAB, converting code with MATCOM is much simpler and more convenient. Based on the author's programming experience, this article takes vc6.0 and MATCOM as an example to describe how to use MATCOM for joint programming of VC and Matlab.
Before installing MATCOM, you must install vc6.0. In the select compiler dialog box that appears during installation, select "yes" (figure 1 ). If you choose whether to install MATLAB, select "no ". Other options are set by default. MATCOM can run independently of Matlab, but requires an external C ++ compiler. It is used to specify the location of MATLAB to locate some system functions required in the compilation file.
Figure 1
After the installation is complete, start the mideva interface (figure 2 ). The mideva integrated development environment includes the command line window, variable List window, command List window, and compilation link information window. Detailed Help documents are provided.
Figure 2
The MATCOM command input method is the same as that of Matlab. If you are installing the Chinese version of the operating system, enter a space before the command. (3 ).
Figure 3
The following describes in detail how to compile m Files and put them into VC.
1. Start mideva, file-> new, and create the following test1.m file:
X = 1:0.; y = sin (x); plot (x, y );
Save the file (4 ).
Figure 4
The default location for saving m Files is MATCOM installation directory matcom45. The default location for saving the generated C ++ files is MATCOM installation directory matcom45debug. In this example, the installation directory of MATCOM is drive C: matcom45debug. Files test1.h, test1.cpp, test1.r, and test1.obj are generated in this directory.
2. Use MFC wizard (exe) in VC to create a project named example based on the dialog box.
Add an idc_button1 button on the panel.
3. Copy the content of test1.cpp under the C: matcom45debug directory to void cexamledlg: onbutton1 (), and (5 ).
Figure 5
4. Set matlib under C: matcom45lib. copy the test1.h files in H and v1_1v files and C: matcom45debug to the example directory of the project, and add the library files and header files to the project in VC: project-> Add project-> files, and select matlib from the directory just copied to example. h, v1_1v, and test1.h files (6 ).
Figure 6
5. Add the following code to examledlg. cpp:
# Include "matlib. H" # include "test1.h"
6. In void cexamledlg: onbutton1 (), add an initialization class library to call the function "initm (matcom_version)" and an end class library to call the function "exitm ()" (7 ).
Figure 7
Run the program and click graph button (8 ).
Figure 8
The release version of the program must be supported by three files: agossag 1.dll, v1_1v. dll, and v1_1.lib. The above is just a simple example of VC and MATCOM interface programming. The functions are not perfect and far below the level required by a software, however, as long as you are familiar with the basic principles and methods of VC and MATCOM interface programming, I believe everyone will be able to compile excellent software.
Download the source code
From http://www.2cto.com/kf/200609/12747.html