VC + + calls the data in MATLAB

Source: Internet
Author: User

Online posts are how to add VC + + data into Matlab, and VC + + calls the data in MATLAB almost no, record a little something again

Configure the programming environment, this article environment is: vs2012+matlab2012b.

The first thing to understand is the MATLAB Engine API function

Next paste the code and effect:

void Test2 () {Engine *ep;if (!) ( EP = Engopen (NULL))) {cout<< "can ' t start matlab engine" <<endl;//messagebox ((HWND) NULL, "can ' t start matlab Engine "," Matlab Draw ", MB_OK);//return 0;} Apply the y array in the MATLAB space and assign the value engevalstring (EP, "y=0:1:511;"); /engine data type Mxarray *gistarry1=null;//gets the pointer of matlab Space y gistarry1=enggetvariable (EP, "Y"); cout<<endl;// Gets the number of dimensions of y Cout<<mxgetn (gistarry1) <<endl;cout<<mxgetm (gistarry1) <<endl;//Gets the real pointer of y double *BB = MXGETPR (Gistarry1); Output data for (int i=0;i<mxgetn (gistarry1), i++) for (int J=0;j<mxgetm (gistarry1); j + +) {cout<<bb[i]<< "  "if (i%15==0) {Cout<<endl;}} Drawing Engevalstring (EP, "X=0:0.01:5.11;plot (x, y);"); Engevalstring (EP, "title (' Matlab Drawing ');"); Engevalstring (EP, "Xlabel (' X ');"); Engevalstring (EP, "Ylabel (' Y ');"); Cout<<endl;system ("pause"); Engclose (EP);//return 0;}
Operating effects such as:


Summary: 1. Data types to be unified



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.