Enable Visual Studio to call MATLAB Extension

Source: Internet
Author: User

1. First, you have to have an extension library of MATLAB. It is better to install a MATLAB.

2. Open Visual Studio, go to the "VC ++ directory" in "Tools"> "options"> "projects and Solutions", and set:

Included files: MATLAB root directory/r2008a/extern/include

Library File: MATLAB root directory/r2008a/extern/lib/Win32/Microsoft

 

 

3. Right-click the project, select "properties", and enter "libmx. Lib libmat. Lib libeng. lib" in the connector. OK.

 

 

4. It will be changed later. Main function production depends on Matlab help.

 

Below is my immaturity package for Matlab:

Cls_mx_matrix is an encapsulation of MATLAB variables.

Cls_mx is an encapsulation of the engine.

 

Class cls_mx_matrix <br/>{< br/> PRIVATE: <br/> mxarray * data; <br/> double * p_data; <br/> int dim_n; <br/> int dim_m; <br/> string str_name; <br/> void reset (mxarray * array) <br/>{< br/> mxdestroyarray (data ); <br/> DATA = array; <br/> p_data = (double *) mxgetdata (data); <br/>}< br/> public: <br/> int get_dim_n () <br/>{< br/> return dim_n; <br/>}< br/> int get_dim_m () <br/>{< br/> return dim_m; <br/>}< br/> void re Size (INT a_n, int a_m) <br/>{< br/> mxdestroyarray (data); <br/> dim_n = a_n; <br/> dim_m = a_m; <br/> DATA = mxcreatedoublematrix (dim_n, dim_m, mxreal); <br/> p_data = (double *) mxgetdata (data ); <br/>}< br/> void get_subscript (cls_mx_matrix & that, int pos_ I _begin, int pos_ I _end, int pos_j_begin, int pos_j_end) <br/>{< br/> int len_ I = pos_ I _end-pos_ I _begin + 1; <br/> int len_j = pos_j_end-pos_j_begin + 1; <br /> That. resize (len_ I, len_j); <br/> for (INT cnt_ I = pos_ I _begin; cnt_ I <= pos_ I _end; cnt_ I ++) <br/>{< br/> for (INT cnt_j = pos_j_begin; cnt_j <= pos_j_end; cnt_j ++) <br/>{< br/> that [make_pair (cnt_ I-pos_ I _begin, cnt_j-pos_j_begin)] = (* This) [make_pair (cnt_ I, cnt_j)]; <br/>}< br/> void operator = (const cls_mx_matrix & that) <br/> {<br/> DATA = That. data; <br/> p_data = That. p_data; <br/> dim_n = That. dim _ N; <br/> dim_m = That. dim_m; <br/>}< br/> cls_mx_matrix (string a_str_name, int a_n, int a_m) <br/>{< br/> str_name = a_str_name; <br/> dim_n = a_n; <br/> dim_m = a_m; <br/> DATA = mxcreatedoublematrix (dim_n, dim_m, mxreal ); <br/> p_data = (double *) mxgetdata (data); <br/>}< br/> cls_mx_matrix (mxarray * array) <br/>{< br/> mxdestroyarray (data); <br/> DATA = array; <br/> p_data = (double *) mxgetdata (data ); <br/>}< br /> Double & operator [] (pair <int, int> POS) <br/>{< br/> return p_data [POS. first * dim_m + POS. second]; <br/>}< br/> ~ Cls_mx_matrix () <br/>{< br/> mxdestroyarray (data); <br/>}< br/> friend class cls_mx; <br/> }; <br/> class cls_mx <br/> {<br/> PRIVATE: <br/> engine * Eng; <br/> Public: <br/> cls_mx () <br/>{< br/> Eng = engopen (null); <br/>}< br/> void set_var (cls_mx_matrix & mx_mat) <br/>{< br/> engputvariable (ENG, mx_mat.str_name.c_str (), mx_mat.data); <br/>}< br/> cls_mx_matrix get_var (string name) <br/>{< br/> return cls_mx_mat Rix (enggetvariable (ENG, name. c_str (); <br/>}< br/> void get_var (cls_mx_matrix & that) <br/>{< br/> that. reset (enggetvariable (ENG, that. str_name.c_str (); <br/>}< br/> void command (string Str) <br/>{< br/> engevalstring (ENG, str. c_str (); <br/>}< br/> ~ Cls_mx () <br/>{< br/> engclose (ENG); <br/>}< br/> }; 

Related Article

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.