Steps for implementing the VC and MATCOM Interfaces

Source: Internet
Author: User
Steps for implementing the VC and MATCOM Interfaces

MATCOM is the first compilation and development software platform launched by Mathworks from MATLAB to C ++. It provides a visual interface for convenient debugging functions and powerful support for the mathematical library.
 
The attention of the majority of technical staff. The current maximum version is matcom4.5.

We can call the. M file compilation by using compile to EXE or DLL under the File menu in MATCOM, and find the generated CPP, EXE, and DLL files under the DEBUG directory of MATCOM.
 
Add the required files to the project of the VC development environment, and then include the header file to implement the call. You can also directly use the scientific computing library in the VC environment, that is, the matrix of MATCOM.

  , It is according
 
MATCOM syntax implements methods similar to MATLAB Functions in VC. However, there is also a method to integrate MATCOM into the VC environment, that is, to install visual MATCOM.
 
Simple operation, you only need to be familiar with Matlab programming, after a simple step, you can easily call MATLAB in the VC environment. The following describes how to install the visual MATCOM development environment.

(1) Copy \ Bin \ usertype. dat file ( The installation path of MATCOM) \ Common \ msdev98 \ bin directory ( The installation path of the VC.

(2) Run visual c ++, select Tools/customize/add-ins and macro files from the menu bar, select Browse, and change the file type to add-ins (. dll ),
 
Selected

  \ Bin \ mvcide. dll file, OK.

(3) In this way, you can see a visual MATCOM toolbar shown in 1 in the Visual C ++ development environment, indicating that the installation is successful.
The following uses the process of solving a linear equations as an example to describe how to implement the MATLABProgramRunning Environment: Win2000, Matlab 6.0, matcom4.5, Visual C ++

(1) Compile the program equation. m in the MATLAB runtime environment.CodeAs follows:

% Equation solutions for Linear Equations
% Linear equations, for example, a * x = B
Function x = equation (A, B)
X = A \ B;
 

(2) A simple console program is used as an example. Other programs are basically the same. Create a Win32 console application project named test in the VC environment.

(3) Click the M ++ icon on the visual MATCOM toolbar and select the saved MATLAB file equation. m for conversion. If the displayed conversion information prompts no error, you can observe this point.
 
M-files, C ++ files created from m-files, Matrix

  . Equation. H, equation. cpp are added to the project directory,
 
Equation. Mak, equation. R, and so on. In this case, a converted file will appear in the VC. If an error is reported in the file, consider whether the program is faulty. You can double-click C ++ files.
Change Equation. m in the folder and then convert it again until there is no error report.

(4) create a file test. cpp under the test project to call the transformed Matlab function. The code is:

# Include "stdio. H"
# Include "matlib. H" // provide the data type, letter/number prototype, and constant used in the converted C ++ code
# Include "equation. H"
Void main ()
{
/* Solving linear equations:
X =
*/
Initm (matcom_version); // initialize the matlib Library
Mm a, B, X; // use the matrix class mm to construct a, B, X.
A = (BR (1), 2,3, semi, 4,5, 6, semi, 7,8, 1 );
// Assign a value to matrix A. BR is matrix. Library
// Macro, used to define the beginning of a matrix; Semi is a constant of the library // used to separate matrix elements of different rows
B = zeros (); // The initialization matrix B is a zero matrix, with three rows and one column
B (1, 1) = 37; B (2, 1) = 85; B (3, 1) = 69; // assign a value to matrix B
X = equation (a, B); // call the transformed function to solve the solution of the linear equations.
For (INT I = 1; I <= x. Rows (); I ++) // display the elements of the solution matrix X.
{
For (Int J = 1; j <= x. Cols (); j ++)
Printf ("X (% d, % d) = % F \ n", I, j, X. R (I, j ));
}
Exitm (); // end the call to the matlib Library
Return;
}

Note: The program involves two member functions. rows () and. cols (), which respectively return the number of rows and columns in the matrix; X. R (I, j) represents the elements in column J of row I of matrix X.

(5) After compilation and running, the result is X (3.000000) = 5.000000 X (8.000000) = x () =, which is consistent with the actual result.

Summary: If the. M file to be converted is not a function, but a set of MATLAB commands, find the. cpp file of the conversion file in the project directory and run the C code
 
Copy it to the function that needs to be called. MATCOM overcomes the disadvantages that the MCC command can only compile one independent. M file. When the compiled. M file depends on other. M files
 
Put the. M file and the. M file to be compiled in the same directory, and insert the. h and. cpp files of the called file to the project developed by VC.

The above is just an example of a simple console project. We can also create other types of projects, as long as the program that needs to call the converted function contains matlib. H AND IN THE RESPONSE LETTER
 
Initialize the matlib library initm (matcom_version); after the call ends, do the end work exitm (); then you can.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.