MATLAB Compile CPP file _matlab

Source: Internet
Author: User

Objective: To get through the channel between MATLAB and VC, realize the VC program using MATLAB, and VC call MATLAB program.

On the blog to achieve the Matlab of the M file compiled into A/C + + file, exe application. This implementation of MATLAB compiler CPP code.

#include "mex.h" 
void mexfunction (int nlhs, Mxarray *plhs[], int nrhs, const mxarray *prhs[]) 
{
int i; 
I=mxgetscalar (Prhs[0]); 
if (i==1) 
  mexprintf ("hello,world!\n"); 
else 
  mexprintf ("Hello everyone.") \ n "); 
}

Above is a simple C + + code, saved into Helloworld.cpp. Briefly explain:

 

is a MEX interface subroutine, the Access program is the interface with MATLAB, to achieve two different memory space communication.

In the MATLAB command line:

Input Mex Helloworld.cpp, compilation successful.

Results:


Note: You must set up the compiler before calling Mex, the compiler settings are very simple, see my last blog, do not say more.


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.