Turn: Use the MATLAB CC ++ Library in VC

xiaoxiao2021-03-05  24

Use MATLAB C / C libraries in VC Author: Yanyan Wei

Download Sample Code 1 Download Sample Code 2 Matlab Widely used in Linear Algebra, Automatic Control Theory, Mathematical Statistics, Digital Signal Processing, Time Series Analysis, Dynamic System Simulation and Others. So if you call Matlab in the VC will greatly reduce programming workload, ensure the accuracy of the program, and inherit the VC powerful function, improve the development efficiency, this article will introduce the specific steps of using the MATLAB function library in VC: After establishing a project in the VC: 1. Setting: Add Path: Add: D: / Matlab6p1 / Extern / Include, D: / Matlab6p1 / Extern / Include / CPP, D: / CPP, D: / Include / CPP, D: / Include / CPP, MATLAB6P1 / EXTERN / lIB lib in project-settings-c / C - category: -preprocessor-preprocessor definitions: column added: MSVC, MSWIND in project-settings-Link-category-Input-Ignore libraries: column added: msvcrt. LIB 2. Add header file: (assuming that the MATLAB file is XM)

#include "matlab.hpp"

#include x.hpp // If there is. M.M, compiled files X.HPP and X.cpp;

Add #include "stdafx.h" in x.cpp. Compilation method in matlab: Use the MCC command to C / C code, the command line parameters are as follows: Generate C file: MCC -T -LC XM Generate C file: MCC -T -L CPP XM Generate Dynamic Link Library Function: MCC -T -w lib: y -t link.lib xm (Y is the generated link file name) 4. Import Link Library:

#pragma comment (Lib, "Libmatlb.lib")

#pragma comment (Lib, "libmx.lib")

#pragma comment (lib, "libmatpm.lib") // c Maths Library

5. The reference code is as follows:

Double d [] = {1, 2, 3, 4};

Mwarray A (2, 2, d);

Mwarray Arrval, Arrvec;

Arrvec = EIG (& Arrval, A);

Double * a = new double [4];

Double * b = new double [4];

For (int i = 0; i <4; i )

{

a [i] = * (mxgetpr (arrval.getdata ()) i); // positive order

B [I] = * (mxgetpr (arrvec.getdata ()) i); // Inverse

}

转载请注明原文地址:https://www.9cbs.com/read-35267.html

New Post(0)