MATLAB uses MCC and VC ++ programming instances

Source: Internet
Author: User

1, StartMATLAB 7, NewMFile, input:

Function myfun (N)
T = 0 : N;
Y = Sin (t );
Plot (y );

Save the file as follows:Myfun. m

2,InMATLABOfCommand windowRun the following command:: MCC-B csglsharedlib: mylib myfunGenerate dynamic link libraryDLL.MATLABGenerates a series of files, includingMylib. h mylib. Lib mylib. dll mylib. CTFIt is what we need here.

3InVC ++Used inMATLABThe generated dynamic link library (*. Dll)

TheTestdllappProject as an example. SetMylib. h mylib. Lib mylib. dll mylib. CTFCopyTestdllappAdd the project to the project directory. ModifyTestdllapp. cppFile:

// Testdllapp. cpp: defines the entry point for the console application.

//
# Include " Stdafx. h "
# Include < Stdio. h >
# Include " Mylib. h "
# Include " Mclmcr. h "

Int OPP ( Int N );
Void Main ( Int Argc, Char * Argv [])
{
Mylibinitialize ();
Double X = 64 ;
Mxarray * T;
T = Mxcreatedoublematrix ( 1 , 1 , Mxreal );
Memcpy (mxgetpr (t ), & X, Sizeof ( Double ));
Mlfmyfun (t );
Mxdestroyarray (t );
Mylibterminate ();
Printf ( " This is a test! \ N " );
Printf ( " % D \ n " , OPP ( 16 ));
}
Int OPP ( Int N) {
ReturnN/4*4+4;
}

4,Use menu Project/Settings, open the Project Settings property page, and enterLinkPage, inObject/library modulesIn the edit box, add a file name.Libmx. Lib libmat. Lib libeng. Lib.

5Compile and runProgram.

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.