In the previous introduction, just briefly introduced VC and MATLAB programming a few simple examples, a lot of key knowledge is not introduced (such as the function of the input and output format, VC invoke Toolbox functions, compiler use, a combination of several methods, etc.) in future articles, this knowledge will be introduced (therefore, the title also changed a bit, hehe, if there is a wrong place, but also hope that everyone a lot of guidance) VC invoke Matlab method has a variety of, in order to have a general understanding of mixed programming, will be commonly used in several ways to introduce:
One, through the MATLAB engine way
MATLAB engine refers to a group of MATLAB provides interface functions, support C language, MATLAB engine using C/S (client/server) mode, MATLAB as a background server, and C program as a foreground client, Through the dynamic control of Windows and the server communication, to the MATLAB engine Transfer command and data information, from the MATLAB engine accept data information. Users can call these interface functions in the foreground application to realize the control of MATLAB engine. The use of this method can almost all the functions of MATLAB, but the need to install MATLAB software on the machine, and the implementation of low efficiency, so in the actual application does not use this method, in the software development is not feasible, I think it is suitable for personal use or demo, so do not intend to introduce.
Second, directly invoke Matlab's C + + Math function library
MATLAB provides a c/C + + language can be used for the call of the library, the math functions, including a large number of c\c++ language rewritten matlab mathematical functions, these functions involving linear algebra, numerical analysis, Fourier transform, polynomial calculation, solving differential equations, etc. and the function library provides a large number of matrix operation functions, in VC can directly use these functions, through these functions in the VC can be conveniently implemented in the MATLAB matrix operation function. Can see this method can be very flexible call Matlab to write applications, but require readers familiar with the c\c++ language, you can see using this method to invoke MATLAB Toolbox function is very difficult. Suitable for users who are more familiar with c\c++ language,
Third, matlab with Matlab Compiler
The function of Matlab compiler is to convert m file into C/s + + code (that is, the MCC command commonly used), this source code needs to be compiled into a standalone application with C + + compiler, the C/s + + file generated in the process of converting m file into a stand-alone application. In principle, can be called by other C/s + + code, the compiler can set the MCC command by the option to compile the M file into a dynamic link library file, c/s file, executable file, such as a series of files. To the Matlab R21.1 so far, matlab compiler M program to convert to C + + code features have many limitations:
Cannot convert script m file, can only convert M function;
Can not use the Matlab object;
Can not use input or eval to operate the MATLAB space variables;
Cannot dynamically name variables, and then use the load or save command to operate;
Cannot process m files with nested calls to other m files;
Can not use the MATLAB inline function;
Four, use the MATLAB Combuilde tool
COM is the abbreviation of Component Object module, which is a common object interface, which can be invoked by any language as long as it is in accordance with this interface standard. matlab6.5 new Combuilder is to use the program written in MATLAB to make COM components, for other language calls. The method is simple, versatile, and can use almost any function of MATLAB (note: Do not support script files, script files to use when the function file), so in the program larger, call the Toolbox function or call function more recommended use, this is also MATLAB company ( MATLAB company is MathWorks company) Recommended use method.